[][src]Struct visiting_ref::VisitingRef

pub struct VisitingRef<T> { /* fields omitted */ }

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]

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]

impl<T> Debug for VisitingRef<T> where
    T: Debug
[src]

impl<T> Deref for VisitingRef<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T> Display for VisitingRef<T> where
    T: Display
[src]

impl<T> From<VisitingMut<T>> for VisitingRef<T>[src]

impl<T> LowerExp for VisitingRef<T> where
    T: LowerExp
[src]

impl<T> LowerHex for VisitingRef<T> where
    T: LowerHex
[src]

impl<T> Octal for VisitingRef<T> where
    T: Octal
[src]

impl<T> Pointer for VisitingRef<T> where
    T: Pointer
[src]

impl<T> UpperExp for VisitingRef<T> where
    T: UpperExp
[src]

impl<T> UpperHex for VisitingRef<T> where
    T: UpperHex
[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for VisitingRef<T>

impl<T> Send for VisitingRef<T> where
    T: Send

impl<T> Sync for VisitingRef<T> where
    T: Send + Sync

impl<T> Unpin for VisitingRef<T> where
    T: Unpin

impl<T> !UnwindSafe for VisitingRef<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.