From 3f433f1cde54f8be56ff20b5e4a7ff509de126b7 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Sun, 29 Dec 2024 09:17:25 +1100 Subject: [PATCH 1/2] 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. --- io/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/io/src/lib.rs b/io/src/lib.rs index 9770f6ce8..35e12b631 100644 --- a/io/src/lib.rs +++ b/io/src/lib.rs @@ -224,6 +224,19 @@ impl> Cursor { /// /// 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 } } From ae129d84ace03fba57bb980cace5aa60ff6bc10e Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Sun, 29 Dec 2024 09:20:39 +1100 Subject: [PATCH 2/2] api: Run just check-api --- api/io/all-features.txt | 2 ++ api/io/alloc-only.txt | 2 ++ api/io/no-features.txt | 2 ++ 3 files changed, 6 insertions(+) diff --git a/api/io/all-features.txt b/api/io/all-features.txt index aef13ac56..af10dd887 100644 --- a/api/io/all-features.txt +++ b/api/io/all-features.txt @@ -214,6 +214,8 @@ pub fn bitcoin_io::BufRead::consume(&mut self, amount: usize) pub fn bitcoin_io::BufRead::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]> pub fn bitcoin_io::Cursor::consume(&mut self, amount: usize) pub fn bitcoin_io::Cursor::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]> +pub fn bitcoin_io::Cursor::get_mut(&mut self) -> &mut T +pub fn bitcoin_io::Cursor::get_ref(&self) -> &T pub fn bitcoin_io::Cursor::inner(&self) -> &T pub fn bitcoin_io::Cursor::into_inner(self) -> T pub fn bitcoin_io::Cursor::new(inner: T) -> Self diff --git a/api/io/alloc-only.txt b/api/io/alloc-only.txt index b0aaeff4e..572cb17e1 100644 --- a/api/io/alloc-only.txt +++ b/api/io/alloc-only.txt @@ -91,6 +91,8 @@ pub fn bitcoin_io::BufRead::consume(&mut self, amount: usize) pub fn bitcoin_io::BufRead::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]> pub fn bitcoin_io::Cursor::consume(&mut self, amount: usize) pub fn bitcoin_io::Cursor::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]> +pub fn bitcoin_io::Cursor::get_mut(&mut self) -> &mut T +pub fn bitcoin_io::Cursor::get_ref(&self) -> &T pub fn bitcoin_io::Cursor::inner(&self) -> &T pub fn bitcoin_io::Cursor::into_inner(self) -> T pub fn bitcoin_io::Cursor::new(inner: T) -> Self diff --git a/api/io/no-features.txt b/api/io/no-features.txt index facd4c3ef..93613d4e6 100644 --- a/api/io/no-features.txt +++ b/api/io/no-features.txt @@ -87,6 +87,8 @@ pub fn bitcoin_io::BufRead::consume(&mut self, amount: usize) pub fn bitcoin_io::BufRead::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]> pub fn bitcoin_io::Cursor::consume(&mut self, amount: usize) pub fn bitcoin_io::Cursor::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]> +pub fn bitcoin_io::Cursor::get_mut(&mut self) -> &mut T +pub fn bitcoin_io::Cursor::get_ref(&self) -> &T pub fn bitcoin_io::Cursor::inner(&self) -> &T pub fn bitcoin_io::Cursor::into_inner(self) -> T pub fn bitcoin_io::Cursor::new(inner: T) -> Self