[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DDO521751WXE.11AAYWCL2CMP0@kernel.org>
Date: Tue, 21 Oct 2025 18:25:13 +0200
From: "Danilo Krummrich" <dakr@...nel.org>
To: "Miguel Ojeda" <miguel.ojeda.sandonis@...il.com>
Cc: <gregkh@...uxfoundation.org>, <rafael@...nel.org>, <ojeda@...nel.org>,
<alex.gaynor@...il.com>, <boqun.feng@...il.com>, <gary@...yguo.net>,
<bjorn3_gh@...tonmail.com>, <lossin@...nel.org>, <a.hindborg@...nel.org>,
<aliceryhl@...gle.com>, <tmgross@...ch.edu>, <mmaurer@...gle.com>,
<rust-for-linux@...r.kernel.org>, <linux-fsdevel@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, "Alexander Viro" <viro@...iv.linux.org.uk>,
"Christian Brauner" <brauner@...nel.org>, "Jan Kara" <jack@...e.cz>
Subject: Re: [PATCH v2 1/8] rust: fs: add file::Offset type alias
On Tue Oct 21, 2025 at 6:00 PM CEST, Miguel Ojeda wrote:
> On Tue, Oct 21, 2025 at 5:26 PM Danilo Krummrich <dakr@...nel.org> wrote:
>>
>> Yeah, I don't think there's any value making this a new type in this case. There
>> are no type invariants, useful methods, etc.
>>
>> In fact, not even the type alias is strictly needed, as i64 would be sufficient
>> as well.
>
> Even if there are no type invariants nor methods, newtypes are still
> useful to prevent bad operations/assignments/...
>
> In general, it would be ideal to have more newtypes (and of course
> avoid primitives for everything), but they come with source code
> overhead, so I was wondering here, because it is usually one chance we
> have to try to go with something stronger vs. the usual C way.
We need arithmetic operations (e.g. checked_add()) and type conversions (e.g.
from/into usize). That'd be quite some code to write that just forwards to the
inner primitive.
So, I think as by now a new type makes sense if there is some reasonable
additional semantics to capture. Of course, if we'd have modular derive macros I
think it is reasonable and makes sense to also do it in cases like this one.
Maybe the action to take from this is to add this to the list of (good first)
issues (not sure this is actually a _good first_ issue though :).
Powered by blists - more mailing lists