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:
parent
39dedf42d4
commit
3f433f1cde
|
@ -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 }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue