Struct qutex::FutureGuard
source · pub struct FutureGuard<T> { /* private fields */ }
Expand description
A future which resolves to a Guard
.
Implementations§
source§impl<T> FutureGuard<T>
impl<T> FutureGuard<T>
sourcepub fn wait(self) -> Result<Guard<T>, Canceled>
pub fn wait(self) -> Result<Guard<T>, Canceled>
Blocks the current thread until this future resolves.
Examples found in repository?
examples/qutex.rs (line 40)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
fn main() {
let thread_count = 100;
let mut threads = Vec::with_capacity(thread_count);
let start_val = 0;
// Create a `Qutex` protecting a start value of zero.
let qutex = Qutex::new(start_val);
// Spawn several threads, each adding 1 to the protected value.
for _ in 0..thread_count {
// Obtain a 'guard' (akin to a `std::sync::MutexGuard`).
let future_val = qutex.clone().lock();
// Add 1 to the protected value. `future_val` is a `FutureGuard` which
// will resolve to a `Guard` providing mutable access to the protected
// value. The guard can be passed between futures combinators and will
// unlock the `Qutex` when dropped.
let future_add = future_val.map(|mut val| {
*val += 1;
});
// Spawn a thread which blocks upon completion of the above lock and
// add operations.
threads.push(thread::spawn(|| {
future_add.wait().unwrap();
}));
}
for thread in threads {
thread.join().unwrap();
}
let val = qutex.lock().wait().unwrap();
assert_eq!(*val, start_val + thread_count);
println!("Qutex final value: {}", *val);
}
Trait Implementations§
source§impl<T: Debug> Debug for FutureGuard<T>
impl<T: Debug> Debug for FutureGuard<T>
source§impl<T> Drop for FutureGuard<T>
impl<T> Drop for FutureGuard<T>
source§impl<T> Future for FutureGuard<T>
impl<T> Future for FutureGuard<T>
§type Error = Canceled
type Error = Canceled
The type of error that this future will resolve with if it fails in a
normal fashion.
source§fn poll(&mut self) -> Poll<Self::Item, Self::Error>
fn poll(&mut self) -> Poll<Self::Item, Self::Error>
Query this future to see if its value has become available, registering
interest if it is not. Read more
source§fn wait(self) -> Result<Self::Item, Self::Error>where
Self: Sized,
fn wait(self) -> Result<Self::Item, Self::Error>where
Self: Sized,
Block the current thread until this future is resolved. Read more
source§fn map<F, U>(self, f: F) -> Map<Self, F>
fn map<F, U>(self, f: F) -> Map<Self, F>
Map this future’s result to a different type, returning a new future of
the resulting type. Read more
source§fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
Map this future’s error to a different error, returning a new future. Read more
source§fn from_err<E>(self) -> FromErr<Self, E>
fn from_err<E>(self) -> FromErr<Self, E>
Map this future’s error to any error implementing
From
for
this future’s Error
, returning a new future. Read moresource§fn then<F, B>(self, f: F) -> Then<Self, B, F>
fn then<F, B>(self, f: F) -> Then<Self, B, F>
Chain on a computation for when a future finished, passing the result of
the future to the provided closure
f
. Read moresource§fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F>
fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F>
Execute another future after this one has resolved successfully. Read more
source§fn or_else<F, B>(self, f: F) -> OrElse<Self, B, F>
fn or_else<F, B>(self, f: F) -> OrElse<Self, B, F>
Execute another future if this one resolves with an error. Read more
source§fn select<B>(self, other: B) -> Select<Self, <B as IntoFuture>::Future>
fn select<B>(self, other: B) -> Select<Self, <B as IntoFuture>::Future>
Waits for either one of two futures to complete. Read more
source§fn select2<B>(self, other: B) -> Select2<Self, <B as IntoFuture>::Future>where
B: IntoFuture,
Self: Sized,
fn select2<B>(self, other: B) -> Select2<Self, <B as IntoFuture>::Future>where
B: IntoFuture,
Self: Sized,
Waits for either one of two differently-typed futures to complete. Read more
source§fn join<B>(self, other: B) -> Join<Self, <B as IntoFuture>::Future>
fn join<B>(self, other: B) -> Join<Self, <B as IntoFuture>::Future>
Joins the result of two futures, waiting for them both to complete. Read more
source§fn join3<B, C>(
self,
b: B,
c: C
) -> Join3<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future>
fn join3<B, C>( self, b: B, c: C ) -> Join3<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future>
Same as
join
, but with more futures.source§fn join4<B, C, D>(
self,
b: B,
c: C,
d: D
) -> Join4<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future, <D as IntoFuture>::Future>where
B: IntoFuture<Error = Self::Error>,
C: IntoFuture<Error = Self::Error>,
D: IntoFuture<Error = Self::Error>,
Self: Sized,
fn join4<B, C, D>(
self,
b: B,
c: C,
d: D
) -> Join4<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future, <D as IntoFuture>::Future>where
B: IntoFuture<Error = Self::Error>,
C: IntoFuture<Error = Self::Error>,
D: IntoFuture<Error = Self::Error>,
Self: Sized,
Same as
join
, but with more futures.source§fn join5<B, C, D, E>(
self,
b: B,
c: C,
d: D,
e: E
) -> Join5<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future, <D as IntoFuture>::Future, <E as IntoFuture>::Future>where
B: IntoFuture<Error = Self::Error>,
C: IntoFuture<Error = Self::Error>,
D: IntoFuture<Error = Self::Error>,
E: IntoFuture<Error = Self::Error>,
Self: Sized,
fn join5<B, C, D, E>(
self,
b: B,
c: C,
d: D,
e: E
) -> Join5<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future, <D as IntoFuture>::Future, <E as IntoFuture>::Future>where
B: IntoFuture<Error = Self::Error>,
C: IntoFuture<Error = Self::Error>,
D: IntoFuture<Error = Self::Error>,
E: IntoFuture<Error = Self::Error>,
Self: Sized,
Same as
join
, but with more futures.source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Convert this future into a single element stream. Read more
source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
Fuse a future such that
poll
will never again be called once it has
completed. Read moresource§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Do something with the item of a future, passing it on. Read more
Create a cloneable handle to this future where all handles will resolve
to the same result. Read more
Auto Trait Implementations§
impl<T> Freeze for FutureGuard<T>
impl<T> !RefUnwindSafe for FutureGuard<T>
impl<T> Send for FutureGuard<T>where
T: Send,
impl<T> Sync for FutureGuard<T>where
T: Send,
impl<T> Unpin for FutureGuard<T>
impl<T> !UnwindSafe for FutureGuard<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