[−][src]Struct visiting_ref::VisitingRef
Container that automatically returns ownership of a value to another async context upon exiting scope, allowing immutable access to the value while active.
VisitingRef
implements Deref
to allow for immutable access to the wrapped value, either
explicitly using the unary *
operator or implicitly by the compiler under various
circumstances. More information can be found in the Deref
trait documentation.
For mutable value access, see VisitingMut
.
Methods
impl<T> VisitingRef<T>
[src]
pub fn new(value: T) -> (Self, Return<T>)
[src]
Creates a new VisitingRef
wrapping the given value, along with a future that resolves back
the wrapped value once the VisitingRef
is dropped.
Examples
use visiting_ref::VisitingRef; let (item, receiver) = VisitingRef::new(5); assert_eq!(*item, 5); drop(item); let original = receiver.await; assert_eq!(original, 5);
pub fn run_with<U, R>(
value: T,
f: impl FnOnce(VisitingRef<T>) -> R
) -> impl Future<Output = (T, U)> where
R: Future<Output = U>,
[src]
value: T,
f: impl FnOnce(VisitingRef<T>) -> R
) -> impl Future<Output = (T, U)> where
R: Future<Output = U>,
Wraps a given T
value in a VisitingRef
and runs an asynchronous closure with the
VisitingRef<T>
as its argument.
Examples
use visiting_ref::VisitingRef; struct Foo { value: i32, } let foo = Foo { value: 27 }; let (foo, result) = VisitingRef::run_with(foo, |foo| async move { foo.value * 3 }).await; assert_eq!(result, 81); assert_eq!(foo.value, 27);
Trait Implementations
impl<T> Binary for VisitingRef<T> where
T: Binary,
[src]
T: Binary,
impl<T> Debug for VisitingRef<T> where
T: Debug,
[src]
T: Debug,
impl<T> Deref for VisitingRef<T>
[src]
impl<T> Display for VisitingRef<T> where
T: Display,
[src]
T: Display,
impl<T> From<VisitingMut<T>> for VisitingRef<T>
[src]
fn from(value: VisitingMut<T>) -> Self
[src]
impl<T> LowerExp for VisitingRef<T> where
T: LowerExp,
[src]
T: LowerExp,
impl<T> LowerHex for VisitingRef<T> where
T: LowerHex,
[src]
T: LowerHex,
impl<T> Octal for VisitingRef<T> where
T: Octal,
[src]
T: Octal,
impl<T> Pointer for VisitingRef<T> where
T: Pointer,
[src]
T: Pointer,
impl<T> UpperExp for VisitingRef<T> where
T: UpperExp,
[src]
T: UpperExp,
impl<T> UpperHex for VisitingRef<T> where
T: UpperHex,
[src]
T: UpperHex,
Auto Trait Implementations
impl<T> !RefUnwindSafe for VisitingRef<T>
impl<T> Send for VisitingRef<T> where
T: Send,
T: Send,
impl<T> Sync for VisitingRef<T> where
T: Send + Sync,
T: Send + Sync,
impl<T> Unpin for VisitingRef<T> where
T: Unpin,
T: Unpin,
impl<T> !UnwindSafe for VisitingRef<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,