RE: [PATCH 1/7] rust: file: add Rust abstraction for `struct file`

From: Benno Lossin
Date: Fri Dec 01 2023 - 12:37:29 EST


On 12/1/23 18:25, David Laight wrote:
> From: Benno Lossin
>> Sent: 01 December 2023 15:14
>>
>> On 12/1/23 16:04, Theodore Ts'o wrote:
>>> On Fri, Dec 01, 2023 at 12:27:40PM +0000, Alice Ryhl wrote:
>>>>
>>>> You can import it with a use statement. For example:
>>>>
>>>> use kernel::file::flags::O_RDONLY;
>>>> // use as O_RDONLY
>>>
>>> That's good to hear,
>
> Except that the examples here seem to imply you can't import
> all of the values without listing them all.

Alice has given an example above, but you might not have noticed:

use kernel::file::flags::*;

// usage:

O_RDONLY
O_APPEND

> From what I've seen of the rust patches the language seems
> to have a lower SNR than ADA or VHDL.
> Too much syntatic 'goop' makes it difficult to see what code
> is actually doing.

This is done for better readability, e.g. when you do not have
rust-analyzer to help you jump to the right definition. But there are
certainly instances where we use the `::*` imports (just look at the
first patch).

> ....
>> Alternatively if we end up with multiple flags modules you can do this
>> (the sixth option from Alice):
>>
>> use kernel::file::flags as file_flags;
>> use kernel::foo::flags as foo_flags;
>>
>> // usage:
>>
>> file_flags::O_RDONLY
>>
>> foo_flags::O_RDONLY
>
> That looks useful for the 'obfuscated rust' competition.
> Consider:
> use kernel::file::flags as foo_flags;
> use kernel::foo::flags as file_flags;

This is no worse than C preprocessor macros doing funky stuff.
We will just have to catch this in review.

--
Cheers,
Benno