diff --git a/wincode/src/io/cursor.rs b/wincode/src/io/cursor.rs index 60b515bd..298fe2dc 100644 --- a/wincode/src/io/cursor.rs +++ b/wincode/src/io/cursor.rs @@ -161,7 +161,7 @@ where self.pos = unsafe { self.pos.unchecked_add(amt) }; } - #[expect(deprecated)] + #[inline] fn consume(&mut self, amt: usize) -> ReadResult<()> { if self.cur_len() < amt { return Err(read_size_limit(amt)); diff --git a/wincode/src/io/mod.rs b/wincode/src/io/mod.rs index 244dd6f7..32e1cfd4 100644 --- a/wincode/src/io/mod.rs +++ b/wincode/src/io/mod.rs @@ -90,7 +90,7 @@ pub trait Reader<'a> { /// Return exactly `N` bytes as `&[u8; N]` without advancing. /// /// Errors if fewer than `N` bytes are available. - #[deprecated(since = "0.4.6", note = "use `take_array`.")] + #[deprecated(since = "0.4.6", note = "use `peek_array`.")] #[expect(deprecated)] fn fill_array(&mut self) -> ReadResult<&[u8; N]> { let src = self.fill_exact(N)?; @@ -99,6 +99,18 @@ pub trait Reader<'a> { Ok(unsafe { &*src.as_ptr().cast::<[u8; N]>() }) } + /// Return exactly `N` bytes as `&[u8; N]` without advancing. + /// + /// Errors if fewer than `N` bytes are available. + #[inline] + #[expect(deprecated)] + fn peek_array(&mut self) -> ReadResult<&[u8; N]> { + let src = self.fill_exact(N)?; + // SAFETY: + // - `fill_exact` ensures we read N bytes. + Ok(unsafe { &*src.as_ptr().cast::<[u8; N]>() }) + } + /// Return exactly `N` bytes as `[u8; N]` and advance by `N`. /// /// Errors if fewer than `N` bytes are available. @@ -202,17 +214,9 @@ pub trait Reader<'a> { /// # Safety /// /// - `amt` must be less than or equal to the number of bytes remaining in the reader. - #[deprecated( - since = "0.4.6", - note = "use one of the `take_*` methods, which automatically advance the reader." - )] unsafe fn consume_unchecked(&mut self, amt: usize); /// Advance the reader exactly `amt` bytes, returning an error if the source does not have enough bytes. - #[deprecated( - since = "0.4.6", - note = "use one of the `take_*` methods, which automatically advance the reader." - )] fn consume(&mut self, amt: usize) -> ReadResult<()>; /// Advance the parent by `n_bytes` and return a [`Reader`] that can elide bounds checks within @@ -249,12 +253,20 @@ pub trait Reader<'a> { /// /// May buffer more bytes if necessary. Errors if no bytes remain. #[inline] - #[deprecated(since = "0.4.6", note = "use `take_byte`.")] + #[deprecated(since = "0.4.6", note = "use `peek_byte`.")] #[expect(deprecated)] fn peek(&mut self) -> ReadResult<&u8> { self.fill_buf(1)?.first().ok_or_else(|| read_size_limit(1)) } + /// Get the next byte without advancing. + /// + /// Errors if no bytes remain. + #[inline] + fn peek_byte(&mut self) -> ReadResult { + Ok(self.peek_array::<1>()?[0]) + } + /// Get a mutable reference to the [`Reader`]. /// /// Useful in situations where one only has an `impl Reader<'de>` that @@ -386,6 +398,11 @@ impl<'a, R: Reader<'a> + ?Sized> Reader<'a> for &mut R { (*self).fill_array() } + #[inline(always)] + fn peek_array(&mut self) -> ReadResult<&[u8; N]> { + (*self).peek_array() + } + #[inline(always)] fn take_array(&mut self) -> ReadResult<[u8; N]> { (*self).take_array() @@ -424,13 +441,11 @@ impl<'a, R: Reader<'a> + ?Sized> Reader<'a> for &mut R { } #[inline(always)] - #[expect(deprecated)] unsafe fn consume_unchecked(&mut self, amt: usize) { (*self).consume_unchecked(amt) } #[inline(always)] - #[expect(deprecated)] fn consume(&mut self, amt: usize) -> ReadResult<()> { (*self).consume(amt) } @@ -446,6 +461,11 @@ impl<'a, R: Reader<'a> + ?Sized> Reader<'a> for &mut R { (*self).peek() } + #[inline(always)] + fn peek_byte(&mut self) -> ReadResult { + (*self).peek_byte() + } + #[inline(always)] fn copy_into_slice(&mut self, dst: &mut [MaybeUninit]) -> ReadResult<()> { (*self).copy_into_slice(dst) diff --git a/wincode/src/io/slice.rs b/wincode/src/io/slice.rs index 9fef5a37..37816df3 100644 --- a/wincode/src/io/slice.rs +++ b/wincode/src/io/slice.rs @@ -177,7 +177,6 @@ impl<'a> Reader<'a> for TrustedSliceReaderZeroCopyMut<'a> { } #[inline] - #[expect(deprecated)] fn consume(&mut self, amt: usize) -> ReadResult<()> { unsafe { Self::consume_unchecked(self, amt) }; Ok(()) @@ -308,7 +307,6 @@ impl<'a> Reader<'a> for &'a [u8] { } #[inline] - #[expect(deprecated)] fn consume(&mut self, amt: usize) -> ReadResult<()> { if self.len() < amt { return Err(read_size_limit(amt)); @@ -376,7 +374,6 @@ impl<'a> Reader<'a> for &'a mut [u8] { } #[inline] - #[expect(deprecated)] fn consume(&mut self, amt: usize) -> ReadResult<()> { if self.len() < amt { return Err(read_size_limit(amt));