Skip to content

Commit b0ec566

Browse files
committed
Merge rust-bitcoin#3855: io: Use get_ref / get_mut API
12a83e1 api: Run just check-api (Tobin C. Harding) 88dfd4e io: Use get_ref / get_mut API (Tobin C. Harding) b7fdb35 io: Move constructors (Tobin C. Harding) Pull request description: 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`. Patch 1 is a trivial code move cleanup. Close: rust-bitcoin#3832 ACKs for top commit: apoelstra: ACK 12a83e1; successfully ran local tests Tree-SHA512: a5ebd806a4914aca050746ffca4930dc0a5bbeffd0d2fdb000af3bebd4d932cb08ec68acd18cd0a8a9cecf3cb7a211e066ebfd2fd62aaf40c5b4b5348e39e6d4
2 parents 33d7052 + 12a83e1 commit b0ec566

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

api/io/all-features.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ pub fn bitcoin_io::FromStd<T>::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]>
242242
pub fn bitcoin_io::FromStd<T>::fill_buf(&mut self) -> std::io::error::Result<&[u8]>
243243
pub fn bitcoin_io::FromStd<T>::flush(&mut self) -> bitcoin_io::Result<()>
244244
pub fn bitcoin_io::FromStd<T>::flush(&mut self) -> std::io::error::Result<()>
245+
pub fn bitcoin_io::FromStd<T>::get_mut(&mut self) -> &mut T
246+
pub fn bitcoin_io::FromStd<T>::get_ref(&self) -> &T
245247
pub fn bitcoin_io::FromStd<T>::inner(&self) -> &T
246248
pub fn bitcoin_io::FromStd<T>::inner_mut(&mut self) -> &mut T
247249
pub fn bitcoin_io::FromStd<T>::into_inner(self) -> T

io/src/bridge.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@ impl<T> FromStd<T> {
1212
#[inline]
1313
pub const fn new(inner: T) -> Self { Self(inner) }
1414

15-
/// Returns the wrapped value.
16-
#[inline]
17-
pub fn into_inner(self) -> T { self.0 }
18-
19-
/// Returns a reference to the wrapped value.
20-
#[inline]
21-
pub fn inner(&self) -> &T { &self.0 }
22-
23-
/// Returns a mutable reference to the wrapped value.
24-
#[inline]
25-
pub fn inner_mut(&mut self) -> &mut T { &mut self.0 }
26-
2715
/// Wraps a mutable reference to IO type.
2816
#[inline]
2917
pub fn new_mut(inner: &mut T) -> &mut Self {
@@ -38,6 +26,28 @@ impl<T> FromStd<T> {
3826
// SAFETY: the type is repr(transparent) and the pointer is created from Box
3927
unsafe { Box::from_raw(Box::into_raw(inner) as *mut Self) }
4028
}
29+
30+
/// Returns the wrapped value.
31+
#[inline]
32+
pub fn into_inner(self) -> T { self.0 }
33+
34+
/// Returns a reference to the wrapped value.
35+
#[inline]
36+
pub fn get_ref(&self) -> &T { &self.0 }
37+
38+
/// Returns a mutable reference to the wrapped value.
39+
#[inline]
40+
pub fn get_mut(&mut self) -> &mut T { &mut self.0 }
41+
42+
/// Returns a reference to the wrapped value.
43+
#[inline]
44+
#[deprecated(since = "TBD", note = "use `get_ref()` instead")]
45+
pub fn inner(&self) -> &T { &self.0 }
46+
47+
/// Returns a mutable reference to the wrapped value.
48+
#[inline]
49+
#[deprecated(since = "TBD", note = "use `get_ref()` instead")]
50+
pub fn inner_mut(&mut self) -> &mut T { &mut self.0 }
4151
}
4252

4353
impl<T: std::io::Read> super::Read for FromStd<T> {

0 commit comments

Comments
 (0)