Re: [PATCH] rust: add C FFI types to the prelude
From: Miguel Ojeda
Date: Mon Apr 14 2025 - 09:23:20 EST
On Mon, Apr 14, 2025 at 10:47 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>
> I wonder if it would make more sense to rephrase this section to first
> say that rfl has type aliases for the C integer types called c_int and
> so on, then mention that they are available in the prelude, and then
> at the end of the section have a note that we don't use the type
> aliases from core::ffi. I think focusing on how to use C integer
> types, rather than technical details about how they are defined, is
> more relevant for a reader who is just looking for coding guidelines.
Hmm... I see what you mean. In other places in the document, we start
comparing with userspace Rust in order to establish a bit of context.
But, more importantly, in this particular guideline I think it is
quite important to say "do not use the usual ones", because they are
actually different types, i.e. it is not just a style thing.
I have thought a couple times about perhaps changing the overall style
of the document to have a 1-liner short summary on each guideline --
some books do something like that consistently. And perhaps an
example, before a longer description. So something like the following,
which is closer to what you are suggesting:
To refer to C types, use the FFI types (aliases) available from
the `kernel` prelude, e.g. ``c_int``.
For instance:
...
Refer to them with a single segment path: e.g. ``c_char`` instead
of ``ffi::c_char`` or ``kernel::ffi::c_char``.
Do not use the `core::ffi::*` types -- they are different and some
do not map to the correct C type.
But even with this style, I think it is important putting the last
sentence in the "1-liner summary". Otherwise, someone may skip the
guideline thinking "oh, OK, it is just a style thing about using just
small paths, I will fix it later", without realizing they are actually
different sets of types unless they read the entire section, no?
Thanks!
Cheers,
Miguel