]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: transmute: add `from_bytes_prefix` family of methods
authorAlexandre Courbot <acourbot@nvidia.com>
Tue, 28 Oct 2025 15:07:36 +0000 (00:07 +0900)
committerAlexandre Courbot <acourbot@nvidia.com>
Wed, 5 Nov 2025 11:29:34 +0000 (20:29 +0900)
commite4ead68a390511384d6af7bc9d00835dd6185e3b
tree676db7fc373c329a3f527f06c3abb67ae0162f4e
parent6553a8f168fb7941ae73d39eccac64f3a2b9b399
rust: transmute: add `from_bytes_prefix` family of methods

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.

Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Message-ID: <20251029-nova-vbios-frombytes-v1-1-ac441ebc1de3@nvidia.com>
Message-ID: <20251101-b4-frombytes-prefix-v1-1-0d9c1fd63b34@nvidia.com>
rust/kernel/transmute.rs