Skip to content

Commit 0ac5b43

Browse files
committed
Merge rust-bitcoin#3823: Improve Cursor ref API
ae129d8 api: Run just check-api (Tobin C. Harding) 3f433f1 Improve Cursor ref API (Tobin C. Harding) Pull request description: 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. ACKs for top commit: apoelstra: ACK ae129d8; successfully ran local tests Tree-SHA512: 664d08cc977c9d6e3319767c49bbabc8f21d681d570f50c514797a7737469cf861af60158ccc1c71d28baed542dabbbca586968144d60691ee0183a549a7b765
2 parents 13c066e + ae129d8 commit 0ac5b43

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

api/io/all-features.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ pub fn bitcoin_io::BufRead::consume(&mut self, amount: usize)
214214
pub fn bitcoin_io::BufRead::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]>
215215
pub fn bitcoin_io::Cursor<T>::consume(&mut self, amount: usize)
216216
pub fn bitcoin_io::Cursor<T>::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]>
217+
pub fn bitcoin_io::Cursor<T>::get_mut(&mut self) -> &mut T
218+
pub fn bitcoin_io::Cursor<T>::get_ref(&self) -> &T
217219
pub fn bitcoin_io::Cursor<T>::inner(&self) -> &T
218220
pub fn bitcoin_io::Cursor<T>::into_inner(self) -> T
219221
pub fn bitcoin_io::Cursor<T>::new(inner: T) -> Self

api/io/alloc-only.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ pub fn bitcoin_io::BufRead::consume(&mut self, amount: usize)
9191
pub fn bitcoin_io::BufRead::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]>
9292
pub fn bitcoin_io::Cursor<T>::consume(&mut self, amount: usize)
9393
pub fn bitcoin_io::Cursor<T>::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]>
94+
pub fn bitcoin_io::Cursor<T>::get_mut(&mut self) -> &mut T
95+
pub fn bitcoin_io::Cursor<T>::get_ref(&self) -> &T
9496
pub fn bitcoin_io::Cursor<T>::inner(&self) -> &T
9597
pub fn bitcoin_io::Cursor<T>::into_inner(self) -> T
9698
pub fn bitcoin_io::Cursor<T>::new(inner: T) -> Self

api/io/no-features.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ pub fn bitcoin_io::BufRead::consume(&mut self, amount: usize)
8787
pub fn bitcoin_io::BufRead::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]>
8888
pub fn bitcoin_io::Cursor<T>::consume(&mut self, amount: usize)
8989
pub fn bitcoin_io::Cursor<T>::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]>
90+
pub fn bitcoin_io::Cursor<T>::get_mut(&mut self) -> &mut T
91+
pub fn bitcoin_io::Cursor<T>::get_ref(&self) -> &T
9092
pub fn bitcoin_io::Cursor<T>::inner(&self) -> &T
9193
pub fn bitcoin_io::Cursor<T>::into_inner(self) -> T
9294
pub fn bitcoin_io::Cursor<T>::new(inner: T) -> Self

io/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,19 @@ impl<T: AsRef<[u8]>> Cursor<T> {
224224
///
225225
/// This is the whole wrapped buffer, including the bytes already read.
226226
#[inline]
227+
pub fn get_ref(&self) -> &T { &self.inner }
228+
229+
/// Returns a mutable reference to the inner buffer.
230+
///
231+
/// This is the whole wrapped buffer, including the bytes already read.
232+
#[inline]
233+
pub fn get_mut(&mut self) -> &mut T { &mut self.inner }
234+
235+
/// Returns a reference to the inner buffer.
236+
///
237+
/// This is the whole wrapped buffer, including the bytes already read.
238+
#[inline]
239+
#[deprecated(since = "TBD", note = "use `get_ref()` instead")]
227240
pub fn inner(&self) -> &T { &self.inner }
228241
}
229242

0 commit comments

Comments
 (0)