From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Danilo Krummrich" <dakr@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND] rust: transmute: add `from_bytes_prefix` family of methods
Date: Sun, 02 Nov 2025 11:05:41 +0900 [thread overview]
Message-ID: <DDXUAGO6JUZ9.1S23GJLS39DBD@nvidia.com> (raw)
In-Reply-To: <DDXEOPKO5RV5.37NXWB7O9AA6K@kernel.org>
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@nvidia.com>
>
> Reviewed-by: Danilo Krummrich <dakr@kernel.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!
next prev parent reply other threads:[~2025-11-02 2:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-01 13:41 [PATCH RESEND] rust: transmute: add `from_bytes_prefix` family of methods Alexandre Courbot
2025-11-01 13:52 ` Danilo Krummrich
2025-11-02 2:05 ` Alexandre Courbot [this message]
2025-11-04 4:55 ` Alexandre Courbot
2025-11-04 9:11 ` Danilo Krummrich
2025-11-05 12:34 ` Miguel Ojeda
2025-11-04 14:12 ` Alice Ryhl
2025-11-05 11:45 ` Alexandre Courbot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DDXUAGO6JUZ9.1S23GJLS39DBD@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).