Skip to content

Commit f64a476

Browse files
committed
Change FromBytes::(mut_)?slice_from_[prefix|suffix] to return Self
Closes google#884
1 parent 4293509 commit f64a476

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

src/lib.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,21 +2148,20 @@ pub unsafe trait FromBytes: FromZeros {
21482148
/// // These are more bytes than are needed to encode two `Pixel`s.
21492149
/// let bytes = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9][..];
21502150
///
2151-
/// let (pixels, rest) = Pixel::slice_from_prefix(bytes, 2).unwrap();
2151+
/// let pixels = Pixel::slice_from_prefix(bytes, 2).unwrap();
21522152
///
21532153
/// assert_eq!(pixels, &[
21542154
/// Pixel { r: 0, g: 1, b: 2, a: 3 },
21552155
/// Pixel { r: 4, g: 5, b: 6, a: 7 },
21562156
/// ]);
21572157
///
2158-
/// assert_eq!(rest, &[8, 9]);
21592158
/// ```
21602159
#[inline]
2161-
fn slice_from_prefix(bytes: &[u8], count: usize) -> Option<(&[Self], &[u8])>
2160+
fn slice_from_prefix(bytes: &[u8], count: usize) -> Option<&[Self]>
21622161
where
21632162
Self: Sized + NoCell,
21642163
{
2165-
Ref::<_, [Self]>::new_slice_from_prefix(bytes, count).map(|(r, b)| (r.into_slice(), b))
2164+
Ref::<_, [Self]>::new_slice_from_prefix(bytes, count).map(|(r, _b)| r.into_slice())
21662165
}
21672166

21682167
/// Interprets the suffix of the given `bytes` as a `&[Self]` with length
@@ -2199,21 +2198,19 @@ pub unsafe trait FromBytes: FromZeros {
21992198
/// // These are more bytes than are needed to encode two `Pixel`s.
22002199
/// let bytes = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9][..];
22012200
///
2202-
/// let (rest, pixels) = Pixel::slice_from_suffix(bytes, 2).unwrap();
2203-
///
2204-
/// assert_eq!(rest, &[0, 1]);
2201+
/// let pixels = Pixel::slice_from_suffix(bytes, 2).unwrap();
22052202
///
22062203
/// assert_eq!(pixels, &[
22072204
/// Pixel { r: 2, g: 3, b: 4, a: 5 },
22082205
/// Pixel { r: 6, g: 7, b: 8, a: 9 },
22092206
/// ]);
22102207
/// ```
22112208
#[inline]
2212-
fn slice_from_suffix(bytes: &[u8], count: usize) -> Option<(&[u8], &[Self])>
2209+
fn slice_from_suffix(bytes: &[u8], count: usize) -> Option<&[Self]>
22132210
where
22142211
Self: Sized + NoCell,
22152212
{
2216-
Ref::<_, [Self]>::new_slice_from_suffix(bytes, count).map(|(b, r)| (b, r.into_slice()))
2213+
Ref::<_, [Self]>::new_slice_from_suffix(bytes, count).map(|(_b, r)| r.into_slice())
22172214
}
22182215

22192216
/// Interprets the given `bytes` as a `&mut [Self]` without copying.
@@ -2301,25 +2298,23 @@ pub unsafe trait FromBytes: FromZeros {
23012298
/// // These are more bytes than are needed to encode two `Pixel`s.
23022299
/// let bytes = &mut [0, 1, 2, 3, 4, 5, 6, 7, 8, 9][..];
23032300
///
2304-
/// let (pixels, rest) = Pixel::mut_slice_from_prefix(bytes, 2).unwrap();
2301+
/// let pixels = Pixel::mut_slice_from_prefix(bytes, 2).unwrap();
23052302
///
23062303
/// assert_eq!(pixels, &[
23072304
/// Pixel { r: 0, g: 1, b: 2, a: 3 },
23082305
/// Pixel { r: 4, g: 5, b: 6, a: 7 },
23092306
/// ]);
23102307
///
2311-
/// assert_eq!(rest, &[8, 9]);
2312-
///
23132308
/// pixels[1] = Pixel { r: 0, g: 0, b: 0, a: 0 };
23142309
///
23152310
/// assert_eq!(bytes, [0, 1, 2, 3, 0, 0, 0, 0, 8, 9]);
23162311
/// ```
23172312
#[inline]
2318-
fn mut_slice_from_prefix(bytes: &mut [u8], count: usize) -> Option<(&mut [Self], &mut [u8])>
2313+
fn mut_slice_from_prefix(bytes: &mut [u8], count: usize) -> Option<&mut [Self]>
23192314
where
23202315
Self: Sized + IntoBytes + NoCell,
23212316
{
2322-
Ref::<_, [Self]>::new_slice_from_prefix(bytes, count).map(|(r, b)| (r.into_mut_slice(), b))
2317+
Ref::<_, [Self]>::new_slice_from_prefix(bytes, count).map(|(r, _b)| r.into_mut_slice())
23232318
}
23242319

23252320
/// Interprets the suffix of the given `bytes` as a `&mut [Self]` with length
@@ -2356,9 +2351,7 @@ pub unsafe trait FromBytes: FromZeros {
23562351
/// // These are more bytes than are needed to encode two `Pixel`s.
23572352
/// let bytes = &mut [0, 1, 2, 3, 4, 5, 6, 7, 8, 9][..];
23582353
///
2359-
/// let (rest, pixels) = Pixel::mut_slice_from_suffix(bytes, 2).unwrap();
2360-
///
2361-
/// assert_eq!(rest, &[0, 1]);
2354+
/// let pixels = Pixel::mut_slice_from_suffix(bytes, 2).unwrap();
23622355
///
23632356
/// assert_eq!(pixels, &[
23642357
/// Pixel { r: 2, g: 3, b: 4, a: 5 },
@@ -2370,11 +2363,11 @@ pub unsafe trait FromBytes: FromZeros {
23702363
/// assert_eq!(bytes, [0, 1, 2, 3, 4, 5, 0, 0, 0, 0]);
23712364
/// ```
23722365
#[inline]
2373-
fn mut_slice_from_suffix(bytes: &mut [u8], count: usize) -> Option<(&mut [u8], &mut [Self])>
2366+
fn mut_slice_from_suffix(bytes: &mut [u8], count: usize) -> Option<&mut [Self]>
23742367
where
23752368
Self: Sized + IntoBytes + NoCell,
23762369
{
2377-
Ref::<_, [Self]>::new_slice_from_suffix(bytes, count).map(|(b, r)| (b, r.into_mut_slice()))
2370+
Ref::<_, [Self]>::new_slice_from_suffix(bytes, count).map(|(_b, r)| r.into_mut_slice())
23782371
}
23792372

23802373
/// Reads a copy of `Self` from `bytes`.

0 commit comments

Comments
 (0)