pub struct Pierce<T>{ /* private fields */ }Expand description
Cache doubly-nested pointers.
A Pierce<T> stores T along with a cached pointer to <T::Target as Deref>::Target.
Implementations§
Source§impl<T> Pierce<T>
impl<T> Pierce<T>
Sourcepub fn new(outer: T) -> Self
pub fn new(outer: T) -> Self
Create a new Pierce.
Create a Pierce out of the given nested pointer.
This method derefs T twice and cache the address where the inner pointer points to.
Deref-ing the created Pierce returns the cached reference directly. deref is not called on T.
Sourcepub fn borrow_outer(&self) -> &T
pub fn borrow_outer(&self) -> &T
Borrow the outer pointer T.
You can then call the methods on &T.
You can even call deref twice on &T yourself to bypass Pierce’s cache:
use std::ops::Deref;
let pierce = Pierce::new(Box::new(Box::new(5)));
let outer: &Box<Box<i32>> = pierce.borrow_outer();
let inner: &Box<i32> = outer.deref();
let target: &i32 = inner.deref();
assert_eq!(*target, 5);Sourcepub fn into_outer(self) -> T
pub fn into_outer(self) -> T
Get the outer pointer T out.
Like into_inner() elsewhere, this consumes the Pierce and return the wrapped pointer.
Trait Implementations§
impl<T> Send for Pierce<T>
impl<T> StableDeref for Pierce<T>
impl<T> Sync for Pierce<T>
Auto Trait Implementations§
impl<T> Freeze for Pierce<T>where
T: Freeze,
impl<T> RefUnwindSafe for Pierce<T>
impl<T> Unpin for Pierce<T>where
T: Unpin,
impl<T> UnwindSafe for Pierce<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more