Improve Cursor ref API

Our `Cursor` is a replacement of sorts for the `std::io::Cursor`. Users
of the `Cursor` are likely to expect the same API so to get a reference
and/or mutable reference users will likely reach for `get_ref` and
`get_mut`. We should provide these.

Deprecate `inner` since it is the same as `get_ref` but less
idiomatically named (should have been `as_inner`).

Add `get_ref` and `get_mut` methods to the `Cursor` type.
This commit is contained in:
Tobin C. Harding 2024-12-29 09:17:25 +11:00
parent 39dedf42d4
commit 3f433f1cde
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 13 additions and 0 deletions

View File

@ -224,6 +224,19 @@ impl<T: AsRef<[u8]>> Cursor<T> {
///
/// This is the whole wrapped buffer, including the bytes already read.
#[inline]
pub fn get_ref(&self) -> &T { &self.inner }
/// Returns a mutable reference to the inner buffer.
///
/// This is the whole wrapped buffer, including the bytes already read.
#[inline]
pub fn get_mut(&mut self) -> &mut T { &mut self.inner }
/// Returns a reference to the inner buffer.
///
/// This is the whole wrapped buffer, including the bytes already read.
#[inline]
#[deprecated(since = "TBD", note = "use `get_ref()` instead")]
pub fn inner(&self) -> &T { &self.inner }
}