Skip to content

Commit

Permalink
[FromBytes] Rename some methods for consistency
Browse files Browse the repository at this point in the history
Add `ref_` prefix to `from_{prefix,suffix}_with_trailing_elements` to be
consistent with other methods.

Makes progress on #871
  • Loading branch information
joshlf committed May 7, 2024
1 parent 4ea4c17 commit 5baa241
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@ pub unsafe trait FromBytes: FromZeros {
/// trailing_dst: [()],
/// }
///
/// let _ = ZSTy::from_prefix_with_trailing_elements(b"UU", 0); // ⚠ Compile Error!
/// let _ = ZSTy::ref_from_prefix_with_trailing_elements(b"UU", 0); // ⚠ Compile Error!
/// ```
///
/// # Examples
Expand All @@ -2240,7 +2240,7 @@ pub unsafe trait FromBytes: FromZeros {
/// // These are more bytes than are needed to encode two `Pixel`s.
/// let bytes = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9][..];
///
/// let (pixels, rest) = Pixel::slice_from_prefix(bytes, 2).unwrap();
/// let (pixels, rest) = <[Pixel]>::ref_from_prefix_with_trailing_elements(bytes, 2).unwrap();
///
/// assert_eq!(pixels, &[
/// Pixel { r: 0, g: 1, b: 2, a: 3 },
Expand All @@ -2251,7 +2251,7 @@ pub unsafe trait FromBytes: FromZeros {
/// ```
#[must_use = "has no side effects"]
#[inline]
fn from_prefix_with_trailing_elements(
fn ref_from_prefix_with_trailing_elements(
bytes: &[u8],
count: usize,
) -> Result<(&Self, &[u8]), CastError<&[u8], Self>>
Expand All @@ -2274,7 +2274,7 @@ pub unsafe trait FromBytes: FromZeros {
where
Self: Sized + Immutable,
{
<[Self]>::from_prefix_with_trailing_elements(bytes, count).ok()
<[Self]>::ref_from_prefix_with_trailing_elements(bytes, count).ok()
}

/// Interprets the suffix of the given `bytes` as a `&[Self]` with length
Expand Down Expand Up @@ -2304,7 +2304,7 @@ pub unsafe trait FromBytes: FromZeros {
/// trailing_dst: [()],
/// }
///
/// let _ = ZSTy::from_suffix_with_trailing_elements(b"UU", 0); // ⚠ Compile Error!
/// let _ = ZSTy::ref_from_suffix_with_trailing_elements(b"UU", 0); // ⚠ Compile Error!
/// ```
///
/// # Examples
Expand All @@ -2326,7 +2326,7 @@ pub unsafe trait FromBytes: FromZeros {
/// // These are more bytes than are needed to encode two `Pixel`s.
/// let bytes = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9][..];
///
/// let (rest, pixels) = Pixel::slice_from_suffix(bytes, 2).unwrap();
/// let (rest, pixels) = <[Pixel]>::ref_from_suffix_with_trailing_elements(bytes, 2).unwrap();
///
/// assert_eq!(rest, &[0, 1]);
///
Expand All @@ -2337,7 +2337,7 @@ pub unsafe trait FromBytes: FromZeros {
/// ```
#[must_use = "has no side effects"]
#[inline]
fn from_suffix_with_trailing_elements(
fn ref_from_suffix_with_trailing_elements(
bytes: &[u8],
count: usize,
) -> Result<(&[u8], &Self), CastError<&[u8], Self>>
Expand All @@ -2360,7 +2360,7 @@ pub unsafe trait FromBytes: FromZeros {
where
Self: Sized + Immutable,
{
<[Self]>::from_suffix_with_trailing_elements(bytes, count).ok()
<[Self]>::ref_from_suffix_with_trailing_elements(bytes, count).ok()
}

#[deprecated(since = "0.8.0", note = "`FromBytes::mut_from` now supports slices")]
Expand Down Expand Up @@ -2459,11 +2459,11 @@ pub unsafe trait FromBytes: FromZeros {
#[doc(hidden)]
#[must_use = "has no side effects"]
#[inline]
fn mut_slice_from_prefix(bytes: &[u8], count: usize) -> Option<(&[Self], &[u8])>
fn mut_slice_from_prefix(bytes: &mut [u8], count: usize) -> Option<(&mut [Self], &mut [u8])>
where
Self: Sized + Immutable,
Self: Sized + IntoBytes + Immutable,
{
<[Self]>::from_prefix_with_trailing_elements(bytes, count).ok()
<[Self]>::mut_from_prefix_with_trailing_elements(bytes, count).ok()
}

/// Interprets the suffix of the given `bytes` as a `&mut [Self]` with length
Expand Down Expand Up @@ -2517,7 +2517,7 @@ pub unsafe trait FromBytes: FromZeros {
/// // These are more bytes than are needed to encode two `Pixel`s.
/// let bytes = &mut [0, 1, 2, 3, 4, 5, 6, 7, 8, 9][..];
///
/// let (rest, pixels) = Pixel::mut_slice_from_suffix(bytes, 2).unwrap();
/// let (rest, pixels) = <[Pixel]>::mut_from_suffix_with_trailing_elements(bytes, 2).unwrap();
///
/// assert_eq!(rest, &[0, 1]);
///
Expand Down

0 comments on commit 5baa241

Please sign in to comment.