Merge rust-bitcoin/rust-bitcoin#3855: io: Use get_ref / get_mut API
12a83e1bf3
api: Run just check-api (Tobin C. Harding)88dfd4e8f2
io: Use get_ref / get_mut API (Tobin C. Harding)b7fdb359e7
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: #3832 ACKs for top commit: apoelstra: ACK 12a83e1bf3b7c8ef8ddfee028b62b2a74ee50585; successfully ran local tests Tree-SHA512: a5ebd806a4914aca050746ffca4930dc0a5bbeffd0d2fdb000af3bebd4d932cb08ec68acd18cd0a8a9cecf3cb7a211e066ebfd2fd62aaf40c5b4b5348e39e6d4
This commit is contained in:
commit
b0ec566742
|
@ -242,6 +242,8 @@ pub fn bitcoin_io::FromStd<T>::fill_buf(&mut self) -> bitcoin_io::Result<&[u8]>
|
|||
pub fn bitcoin_io::FromStd<T>::fill_buf(&mut self) -> std::io::error::Result<&[u8]>
|
||||
pub fn bitcoin_io::FromStd<T>::flush(&mut self) -> bitcoin_io::Result<()>
|
||||
pub fn bitcoin_io::FromStd<T>::flush(&mut self) -> std::io::error::Result<()>
|
||||
pub fn bitcoin_io::FromStd<T>::get_mut(&mut self) -> &mut T
|
||||
pub fn bitcoin_io::FromStd<T>::get_ref(&self) -> &T
|
||||
pub fn bitcoin_io::FromStd<T>::inner(&self) -> &T
|
||||
pub fn bitcoin_io::FromStd<T>::inner_mut(&mut self) -> &mut T
|
||||
pub fn bitcoin_io::FromStd<T>::into_inner(self) -> T
|
||||
|
|
|
@ -12,18 +12,6 @@ impl<T> FromStd<T> {
|
|||
#[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,28 @@ impl<T> FromStd<T> {
|
|||
// 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 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 }
|
||||
}
|
||||
|
||||
impl<T: std::io::Read> super::Read for FromStd<T> {
|
||||
|
|
Loading…
Reference in New Issue