rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "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: Sat, 01 Nov 2025 14:52:00 +0100	[thread overview]
Message-ID: <DDXEOPKO5RV5.37NXWB7O9AA6K@kernel.org> (raw)
In-Reply-To: <20251101-b4-frombytes-prefix-v1-1-0d9c1fd63b34@nvidia.com>

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]`.

  reply	other threads:[~2025-11-01 13:52 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 [this message]
2025-11-02  2:05   ` Alexandre Courbot
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=DDXEOPKO5RV5.37NXWB7O9AA6K@kernel.org \
    --to=dakr@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --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).