diff options
author | Alexandre Courbot <acourbot@nvidia.com> | 2025-08-26 13:07:37 +0900 |
---|---|---|
committer | Alexandre Courbot <acourbot@nvidia.com> | 2025-08-28 22:31:17 +0900 |
commit | 09f90256e8902793f594517ef440698585eb3595 (patch) | |
tree | 57ac51d5a337b28f3358660b36b8c4b7b57b4860 /rust/kernel/alloc/allocator | |
parent | 72031905cf2e36519a98b5becbe62dc10ebb4b97 (diff) |
rust: transmute: add `from_bytes_copy` method to `FromBytes` trait
`FromBytes::from_bytes` comes with a few practical limitations:
- It requires the bytes slice to have the same alignment as the returned
type, which might not be guaranteed in the case of a byte stream,
- It returns a reference, requiring the returned type to implement
`Clone` if one wants to keep the value for longer than the lifetime of
the slice.
To overcome these when needed, add a `from_bytes_copy` with a default
implementation in the trait. `from_bytes_copy` returns an owned value
that is populated using an unaligned read, removing the lifetime
constraint and making it usable even on non-aligned byte slices.
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Link: https://lore.kernel.org/r/20250826-nova_firmware-v2-1-93566252fe3a@nvidia.com
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Diffstat (limited to 'rust/kernel/alloc/allocator')
0 files changed, 0 insertions, 0 deletions