Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docs for #526 #559

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ pub unsafe trait FromBytes: FromZeroes {
/// Interprets the prefix of the given `bytes` as a `&Self` without copying.
///
/// `ref_from_prefix` returns a reference to the first `size_of::<Self>()`
/// bytes of `bytes`. If `bytes.len() != size_of::<T>()` or `bytes` is not
/// bytes of `bytes`. If `bytes.len() < size_of::<T>()` or `bytes` is not
/// aligned to `align_of::<T>()`, this returns `None`.
///
/// To also access the prefix bytes, use [`Ref::new_from_prefix`]. Then,
Expand All @@ -1237,7 +1237,7 @@ pub unsafe trait FromBytes: FromZeroes {
/// Interprets the suffix of the given `bytes` as a `&Self` without copying.
///
/// `ref_from_suffix` returns a reference to the last `size_of::<Self>()`
/// bytes of `bytes`. If `bytes.len() != size_of::<T>()` or the suffix of
/// bytes of `bytes`. If `bytes.len() < size_of::<T>()` or the suffix of
/// `bytes` is not aligned to `align_of::<T>()`, this returns `None`.
///
/// To also access the suffix bytes, use [`Ref::new_from_suffix`]. Then,
Expand Down Expand Up @@ -1265,7 +1265,7 @@ pub unsafe trait FromBytes: FromZeroes {
/// Interprets the prefix of the given `bytes` as a `&mut Self` without copying.
///
/// `mut_from_prefix` returns a reference to the first `size_of::<Self>()`
/// bytes of `bytes`. If `bytes.len() != size_of::<T>()` or `bytes` is not
/// bytes of `bytes`. If `bytes.len() < size_of::<T>()` or `bytes` is not
/// aligned to `align_of::<T>()`, this returns `None`.
///
/// To also access the prefix bytes, use [`Ref::new_from_prefix`]. Then,
Expand All @@ -1281,7 +1281,7 @@ pub unsafe trait FromBytes: FromZeroes {
/// Interprets the suffix of the given `bytes` as a `&mut Self` without copying.
///
/// `mut_from_suffix` returns a reference to the last `size_of::<Self>()`
/// bytes of `bytes`. If `bytes.len() != size_of::<T>()` or the suffix of
/// bytes of `bytes`. If `bytes.len() < size_of::<T>()` or the suffix of
/// `bytes` is not aligned to `align_of::<T>()`, this returns `None`.
///
/// To also access the suffix bytes, use [`Ref::new_from_suffix`]. Then,
Expand Down Expand Up @@ -4911,6 +4911,8 @@ mod tests {
);
let suffix = AU64::mut_from(&mut buf.t[8..]).unwrap();
suffix.0 = 0x0101010101010101;
// The `[u8:9]` is a non-half size of the full buffer, which would catch
// `from_prefix` having the same implementation as `from_suffix` (issues #506, #511).
assert_eq!(<[u8; 9]>::ref_from_suffix(&buf.t[..]).unwrap(), &[7u8, 1, 1, 1, 1, 1, 1, 1, 1]);
let suffix = AU64::mut_from_suffix(&mut buf.t[1..]).unwrap();
suffix.0 = 0x0202020202020202;
Expand Down