[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <DDXUAGO6JUZ9.1S23GJLS39DBD@nvidia.com>
Date: Sun, 02 Nov 2025 11:05:41 +0900
From: "Alexandre Courbot" <acourbot@...dia.com>
To: "Danilo Krummrich" <dakr@...nel.org>, "Alexandre Courbot"
<acourbot@...dia.com>
Cc: "Miguel Ojeda" <ojeda@...nel.org>, "Alex Gaynor"
<alex.gaynor@...il.com>, "Boqun Feng" <boqun.feng@...il.com>, "Gary Guo"
<gary@...yguo.net>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>, "Benno Lossin" <lossin@...nel.org>, "Andreas
Hindborg" <a.hindborg@...nel.org>, "Alice Ryhl" <aliceryhl@...gle.com>,
"Trevor Gross" <tmgross@...ch.edu>, <rust-for-linux@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH RESEND] rust: transmute: add `from_bytes_prefix` family
of methods
On Sat Nov 1, 2025 at 10:52 PM JST, Danilo Krummrich wrote:
> On Sat Nov 1, 2025 at 2:41 PM CET, Alexandre Courbot wrote:
>> The `from_bytes*` family of functions expect a slice of the exact same
>> size as the requested type. This can be sometimes cumbersome for callers
>> that deal with dynamic stream of data that needs to be manually cut
>> before each invocation of `from_bytes`.
>>
>> To simplify such callers, introduce a new `from_bytes*_prefix` family of
>> methods, which split the input slice at the index required for the
>> equivalent `from_bytes` method to succeed, and return its result
>> alongside with the remainder of the slice.
>>
>> This design is inspired by zerocopy's `try_*_from_prefix` family of
>> methods.
>>
>> Signed-off-by: Alexandre Courbot <acourbot@...dia.com>
>
> Reviewed-by: Danilo Krummrich <dakr@...nel.org>
>
> One nit below:
>
>> + /// Converts the beginning of `bytes` to a reference to `Self`.
>> + ///
>> + /// This method is similar to [`Self::from_bytes`], with the difference that `bytes` does not
>> + /// need to be the same size of `Self` - the appropriate portion is cut from the beginning of
>> + /// `bytes`, and the remainder returned alongside the result.
>
> Maybe "alongside `&Self`"? "alongside the result" sounds a bit like the method
> would return `Result<&Self>, &[u8]`.
Thanks, that remove the ambiguity indeed!
Powered by blists - more mailing lists