From b7fdb359e76a2ec170d7b9abc704a7a29a0890c6 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Sat, 4 Jan 2025 15:38:03 +1100 Subject: [PATCH 1/3] io: Move constructors Put all the constructors together. Internal change only. --- io/src/bridge.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/io/src/bridge.rs b/io/src/bridge.rs index 204a77a51..182f770c9 100644 --- a/io/src/bridge.rs +++ b/io/src/bridge.rs @@ -12,18 +12,6 @@ impl FromStd { #[inline] pub const fn new(inner: T) -> Self { Self(inner) } - /// Returns the wrapped value. - #[inline] - pub fn into_inner(self) -> T { self.0 } - - /// Returns a reference to the wrapped value. - #[inline] - pub fn inner(&self) -> &T { &self.0 } - - /// Returns a mutable reference to the wrapped value. - #[inline] - pub fn inner_mut(&mut self) -> &mut T { &mut self.0 } - /// Wraps a mutable reference to IO type. #[inline] pub fn new_mut(inner: &mut T) -> &mut Self { @@ -38,6 +26,18 @@ impl FromStd { // SAFETY: the type is repr(transparent) and the pointer is created from Box unsafe { Box::from_raw(Box::into_raw(inner) as *mut Self) } } + + /// Returns the wrapped value. + #[inline] + pub fn into_inner(self) -> T { self.0 } + + /// Returns a reference to the wrapped value. + #[inline] + pub fn inner(&self) -> &T { &self.0 } + + /// Returns a mutable reference to the wrapped value. + #[inline] + pub fn inner_mut(&mut self) -> &mut T { &mut self.0 } } impl super::Read for FromStd { From 88dfd4e8f2b12f5e50caab16481c4e0a8935c9f7 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Sat, 4 Jan 2025 15:39:50 +1100 Subject: [PATCH 2/3] io: Use get_ref / get_mut API Currently in the `bridge` module to get a reference and mutable reference we provide the `as_inner` and `inner_mut` functions. These names are not in line with the `std::io` module which favours `get_ref` and `get_mut`. Add inherent functions `get_ref` and `get_mut` for accessing the wrapped value in `bridge::ToStd` and deprecate `as_inner` and `inner_mut`. To convince yourself this API is correct grep the stdlib `io` module for `fn get_ref` as opposed to `fn as_ref`. Close: #3832 --- io/src/bridge.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/io/src/bridge.rs b/io/src/bridge.rs index 182f770c9..a979f7387 100644 --- a/io/src/bridge.rs +++ b/io/src/bridge.rs @@ -33,10 +33,20 @@ impl FromStd { /// Returns a reference to the wrapped value. #[inline] + pub fn get_ref(&self) -> &T { &self.0 } + + /// Returns a mutable reference to the wrapped value. + #[inline] + pub fn get_mut(&mut self) -> &mut T { &mut self.0 } + + /// Returns a reference to the wrapped value. + #[inline] + #[deprecated(since = "TBD", note = "use `get_ref()` instead")] pub fn inner(&self) -> &T { &self.0 } /// Returns a mutable reference to the wrapped value. #[inline] + #[deprecated(since = "TBD", note = "use `get_ref()` instead")] pub fn inner_mut(&mut self) -> &mut T { &mut self.0 } } From 12a83e1bf3b7c8ef8ddfee028b62b2a74ee50585 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Sat, 4 Jan 2025 15:53:12 +1100 Subject: [PATCH 3/3] api: Run just check-api --- api/io/all-features.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/io/all-features.txt b/api/io/all-features.txt index af10dd887..055e6305d 100644 --- a/api/io/all-features.txt +++ b/api/io/all-features.txt @@ -242,6 +242,8 @@ pub fn bitcoin_io::FromStd::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]> pub fn bitcoin_io::FromStd::fill_buf(&mut self) -> std::io::error::Result<&[u8]> pub fn bitcoin_io::FromStd::flush(&mut self) -> bitcoin_io::Result<()> pub fn bitcoin_io::FromStd::flush(&mut self) -> std::io::error::Result<()> +pub fn bitcoin_io::FromStd::get_mut(&mut self) -> &mut T +pub fn bitcoin_io::FromStd::get_ref(&self) -> &T pub fn bitcoin_io::FromStd::inner(&self) -> &T pub fn bitcoin_io::FromStd::inner_mut(&mut self) -> &mut T pub fn bitcoin_io::FromStd::into_inner(self) -> T