Skip to content

Commit f405033

Browse files
authored
[FromBytes] Rename some methods for consistency (#1210)
Add `ref_` prefix to `from_{prefix,suffix}_with_trailing_elements` to be consistent with other methods. Makes progress on #871
1 parent 7dc82e7 commit f405033

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/lib.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -2218,7 +2218,7 @@ pub unsafe trait FromBytes: FromZeros {
22182218
/// trailing_dst: [()],
22192219
/// }
22202220
///
2221-
/// let _ = ZSTy::from_prefix_with_trailing_elements(b"UU", 0); // ⚠ Compile Error!
2221+
/// let _ = ZSTy::ref_from_prefix_with_trailing_elements(b"UU", 0); // ⚠ Compile Error!
22222222
/// ```
22232223
///
22242224
/// # Examples
@@ -2240,7 +2240,7 @@ pub unsafe trait FromBytes: FromZeros {
22402240
/// // These are more bytes than are needed to encode two `Pixel`s.
22412241
/// let bytes = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9][..];
22422242
///
2243-
/// let (pixels, rest) = Pixel::slice_from_prefix(bytes, 2).unwrap();
2243+
/// let (pixels, rest) = <[Pixel]>::ref_from_prefix_with_trailing_elements(bytes, 2).unwrap();
22442244
///
22452245
/// assert_eq!(pixels, &[
22462246
/// Pixel { r: 0, g: 1, b: 2, a: 3 },
@@ -2251,7 +2251,7 @@ pub unsafe trait FromBytes: FromZeros {
22512251
/// ```
22522252
#[must_use = "has no side effects"]
22532253
#[inline]
2254-
fn from_prefix_with_trailing_elements(
2254+
fn ref_from_prefix_with_trailing_elements(
22552255
bytes: &[u8],
22562256
count: usize,
22572257
) -> Result<(&Self, &[u8]), CastError<&[u8], Self>>
@@ -2274,7 +2274,7 @@ pub unsafe trait FromBytes: FromZeros {
22742274
where
22752275
Self: Sized + Immutable,
22762276
{
2277-
<[Self]>::from_prefix_with_trailing_elements(bytes, count).ok()
2277+
<[Self]>::ref_from_prefix_with_trailing_elements(bytes, count).ok()
22782278
}
22792279

22802280
/// Interprets the suffix of the given `bytes` as a `&[Self]` with length
@@ -2304,7 +2304,7 @@ pub unsafe trait FromBytes: FromZeros {
23042304
/// trailing_dst: [()],
23052305
/// }
23062306
///
2307-
/// let _ = ZSTy::from_suffix_with_trailing_elements(b"UU", 0); // ⚠ Compile Error!
2307+
/// let _ = ZSTy::ref_from_suffix_with_trailing_elements(b"UU", 0); // ⚠ Compile Error!
23082308
/// ```
23092309
///
23102310
/// # Examples
@@ -2326,7 +2326,7 @@ pub unsafe trait FromBytes: FromZeros {
23262326
/// // These are more bytes than are needed to encode two `Pixel`s.
23272327
/// let bytes = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9][..];
23282328
///
2329-
/// let (rest, pixels) = Pixel::slice_from_suffix(bytes, 2).unwrap();
2329+
/// let (rest, pixels) = <[Pixel]>::ref_from_suffix_with_trailing_elements(bytes, 2).unwrap();
23302330
///
23312331
/// assert_eq!(rest, &[0, 1]);
23322332
///
@@ -2337,7 +2337,7 @@ pub unsafe trait FromBytes: FromZeros {
23372337
/// ```
23382338
#[must_use = "has no side effects"]
23392339
#[inline]
2340-
fn from_suffix_with_trailing_elements(
2340+
fn ref_from_suffix_with_trailing_elements(
23412341
bytes: &[u8],
23422342
count: usize,
23432343
) -> Result<(&[u8], &Self), CastError<&[u8], Self>>
@@ -2360,7 +2360,7 @@ pub unsafe trait FromBytes: FromZeros {
23602360
where
23612361
Self: Sized + Immutable,
23622362
{
2363-
<[Self]>::from_suffix_with_trailing_elements(bytes, count).ok()
2363+
<[Self]>::ref_from_suffix_with_trailing_elements(bytes, count).ok()
23642364
}
23652365

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

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

0 commit comments

Comments
 (0)