pub struct Exclusive<T>where
T: ?Sized,{ /* private fields */ }
exclusive_wrapper
)Expand description
Exclusive
provides only mutable access, also referred to as exclusive
access to the underlying value. It provides no immutable, or shared
access to the underlying value.
While this may seem not very useful, it allows Exclusive
to unconditionally
implement Sync
. Indeed, the safety requirements of Sync
state that for Exclusive
to be Sync
, it must be sound to share across threads, that is, it must be sound
for &Exclusive
to cross thread boundaries. By design, a &Exclusive
has no API
whatsoever, making it useless, thus harmless, thus memory safe.
Certain constructs like Future
s can only be used with exclusive access,
and are often Send
but not Sync
, so Exclusive
can be used as hint to the
Rust compiler that something is Sync
in practice.
ยงExamples
Using a non-Sync
future prevents the wrapping struct from being Sync
use core::cell::Cell;
async fn other() {}
fn assert_sync<T: Sync>(t: T) {}
struct State<F> {
future: F
}
assert_sync(State {
future: async {
let cell = Cell::new(1);
let cell_ref = &cell;
other().await;
let value = cell_ref.get();
}
});
Exclusive
ensures the struct is Sync
without stripping the future of its
functionality.
#![feature(exclusive_wrapper)]
use core::cell::Cell;
use core::sync::Exclusive;
async fn other() {}
fn assert_sync<T: Sync>(t: T) {}
struct State<F> {
future: Exclusive<F>
}
assert_sync(State {
future: Exclusive::new(async {
let cell = Cell::new(1);
let cell_ref = &cell;
other().await;
let value = cell_ref.get();
})
});
ยงParallels with a mutex
In some sense, Exclusive
can be thought of as a compile-time version of
a mutex, as the borrow-checker guarantees that only one &mut
can exist
for any value. This is a parallel with the fact that
&
and &mut
references together can be thought of as a compile-time
version of a read-write lock.
Implementationsยง
Sourceยงimpl<T> Exclusive<T>where
T: ?Sized,
impl<T> Exclusive<T>where
T: ?Sized,
Sourcepub const fn get_mut(&mut self) -> &mut T
๐ฌThis is a nightly-only experimental API. (exclusive_wrapper
)
pub const fn get_mut(&mut self) -> &mut T
exclusive_wrapper
)Gets exclusive access to the underlying value.
Sourcepub const fn get_pin_mut(self: Pin<&mut Exclusive<T>>) -> Pin<&mut T>
๐ฌThis is a nightly-only experimental API. (exclusive_wrapper
)
pub const fn get_pin_mut(self: Pin<&mut Exclusive<T>>) -> Pin<&mut T>
exclusive_wrapper
)Gets pinned exclusive access to the underlying value.
Exclusive
is considered to structurally pin the underlying
value, which means unpinned Exclusive
s can produce unpinned
access to the underlying value, but pinned Exclusive
s only
produce pinned access to the underlying value.
Sourcepub const fn from_mut(r: &mut T) -> &mut Exclusive<T> โ
๐ฌThis is a nightly-only experimental API. (exclusive_wrapper
)
pub const fn from_mut(r: &mut T) -> &mut Exclusive<T> โ
exclusive_wrapper
)Build a mutable reference to an Exclusive<T>
from
a mutable reference to a T
. This allows you to skip
building an Exclusive
with Exclusive::new
.
Sourcepub const fn from_pin_mut(r: Pin<&mut T>) -> Pin<&mut Exclusive<T>>
๐ฌThis is a nightly-only experimental API. (exclusive_wrapper
)
pub const fn from_pin_mut(r: Pin<&mut T>) -> Pin<&mut Exclusive<T>>
exclusive_wrapper
)Build a pinned mutable reference to an Exclusive<T>
from
a pinned mutable reference to a T
. This allows you to skip
building an Exclusive
with Exclusive::new
.
Trait Implementationsยง
Sourceยงimpl<R, G> Coroutine<R> for Exclusive<G>
impl<R, G> Coroutine<R> for Exclusive<G>
Sourceยงtype Yield = <G as Coroutine<R>>::Yield
type Yield = <G as Coroutine<R>>::Yield
coroutine_trait
)impl<T> Sync for Exclusive<T>where
T: ?Sized,
Auto Trait Implementationsยง
impl<T> Freeze for Exclusive<T>
impl<T> RefUnwindSafe for Exclusive<T>where
T: RefUnwindSafe + ?Sized,
impl<T> Send for Exclusive<T>
impl<T> Unpin for Exclusive<T>
impl<T> UnwindSafe for Exclusive<T>where
T: UnwindSafe + ?Sized,
Blanket Implementationsยง
Sourceยงimpl<F, T, U, R, E> AsyncPredicate<T> for F
impl<F, T, U, R, E> AsyncPredicate<T> for F
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
Sourceยงimpl<T> FutureExt for T
impl<T> FutureExt for T
Sourceยงfn map<U, F>(self, f: F) -> Map<Self, F> โ
fn map<U, F>(self, f: F) -> Map<Self, F> โ
Sourceยงfn map_into<U>(self) -> MapInto<Self, U> โ
fn map_into<U>(self) -> MapInto<Self, U> โ
Sourceยงfn then<Fut, F>(self, f: F) -> Then<Self, Fut, F> โ
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F> โ
f
. Read moreSourceยงfn left_future<B>(self) -> Either<Self, B> โ
fn left_future<B>(self) -> Either<Self, B> โ
Sourceยงfn right_future<A>(self) -> Either<A, Self> โ
fn right_future<A>(self) -> Either<A, Self> โ
Sourceยงfn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Sourceยงfn flatten(self) -> Flatten<Self> โ
fn flatten(self) -> Flatten<Self> โ
Sourceยงfn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
Sourceยงfn fuse(self) -> Fuse<Self> โwhere
Self: Sized,
fn fuse(self) -> Fuse<Self> โwhere
Self: Sized,
poll
will never again be called once it has
completed. This method can be used to turn any Future
into a
FusedFuture
. Read moreSourceยงfn inspect<F>(self, f: F) -> Inspect<Self, F> โ
fn inspect<F>(self, f: F) -> Inspect<Self, F> โ
Sourceยงfn catch_unwind(self) -> CatchUnwind<Self> โwhere
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self> โwhere
Self: Sized + UnwindSafe,
Sourceยงfn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
()
on completion and sends
its output to another future on a separate task. Read moreSourceยงfn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
Sourceยงfn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
Sourceยงfn unit_error(self) -> UnitError<Self> โwhere
Self: Sized,
fn unit_error(self) -> UnitError<Self> โwhere
Self: Sized,
Future<Output = T>
into a
TryFuture<Ok = T, Error = ()
>.Sourceยงfn never_error(self) -> NeverError<Self> โwhere
Self: Sized,
fn never_error(self) -> NeverError<Self> โwhere
Self: Sized,
Future<Output = T>
into a
TryFuture<Ok = T, Error = Never
>.Sourceยงimpl<T> Instrument for T
impl<T> Instrument for T
Sourceยงfn instrument(self, span: Span) -> Instrumented<Self> โ
fn instrument(self, span: Span) -> Instrumented<Self> โ
Sourceยงfn in_current_span(self) -> Instrumented<Self> โ
fn in_current_span(self) -> Instrumented<Self> โ
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self> โ
fn into_either(self, into_left: bool) -> Either<Self, Self> โ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSourceยงimpl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Sourceยงtype IntoFuture = F
type IntoFuture = F
Sourceยงfn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Sourceยงimpl<I, O, E, F> Parser<I> for F
impl<I, O, E, F> Parser<I> for F
Sourceยงfn process<OM>(
&mut self,
i: I,
) -> Result<(I, <<OM as OutputMode>::Output as Mode>::Output<<F as Parser<I>>::Output>), Err<<F as Parser<I>>::Error, <<OM as OutputMode>::Error as Mode>::Output<<F as Parser<I>>::Error>>>where
OM: OutputMode,
fn process<OM>(
&mut self,
i: I,
) -> Result<(I, <<OM as OutputMode>::Output as Mode>::Output<<F as Parser<I>>::Output>), Err<<F as Parser<I>>::Error, <<OM as OutputMode>::Error as Mode>::Output<<F as Parser<I>>::Error>>>where
OM: OutputMode,
Result
containing
either the remaining input and the output value, or an errorSourceยงfn parse(
&mut self,
input: Input,
) -> Result<(Input, Self::Output), Err<Self::Error>>
fn parse( &mut self, input: Input, ) -> Result<(Input, Self::Output), Err<Self::Error>>
Result
containing
either the remaining input and the output value, or an errorSourceยงfn parse_complete(
&mut self,
input: Input,
) -> Result<(Input, Self::Output), Err<Self::Error>>
fn parse_complete( &mut self, input: Input, ) -> Result<(Input, Self::Output), Err<Self::Error>>
Result
containing
either the remaining input and the output value, or an errorSourceยงfn map_res<G, O2, E2>(self, g: G) -> MapRes<Self, G>
fn map_res<G, O2, E2>(self, g: G) -> MapRes<Self, G>
Result
over the result of a parser.Sourceยงfn map_opt<G, O2>(self, g: G) -> MapOpt<Self, G>
fn map_opt<G, O2>(self, g: G) -> MapOpt<Self, G>
Option
over the result of a parser.Sourceยงfn flat_map<G, H>(self, g: G) -> FlatMap<Self, G>
fn flat_map<G, H>(self, g: G) -> FlatMap<Self, G>
Sourceยงfn and_then<G>(self, g: G) -> AndThen<Self, G>
fn and_then<G>(self, g: G) -> AndThen<Self, G>
Sourceยงfn and<G, O2>(self, g: G) -> And<Self, G>
fn and<G, O2>(self, g: G) -> And<Self, G>
Sourceยงimpl<'a, I, O, E, F> Parser<I, O, E> for F
impl<'a, I, O, E, F> Parser<I, O, E> for F
Sourceยงfn parse(&mut self, i: I) -> Result<(I, O), Err<E>>
fn parse(&mut self, i: I) -> Result<(I, O), Err<E>>
Result
containing
either the remaining input and the output value, or an errorSourceยงfn flat_map<G, H, O2>(self, g: G) -> FlatMap<Self, G, O>
fn flat_map<G, H, O2>(self, g: G) -> FlatMap<Self, G, O>
Sourceยงfn and_then<G, O2>(self, g: G) -> AndThen<Self, G, O>
fn and_then<G, O2>(self, g: G) -> AndThen<Self, G, O>
Sourceยงfn and<G, O2>(self, g: G) -> And<Self, G>
fn and<G, O2>(self, g: G) -> And<Self, G>
Sourceยงimpl<'a, I, O, E, F> Parser<I, O, E> for F
impl<'a, I, O, E, F> Parser<I, O, E> for F
Sourceยงfn parse(&mut self, input: I) -> Result<O, ParseError<I, E>>
fn parse(&mut self, input: I) -> Result<O, ParseError<I, E>>
input
, generating O
from itSourceยงfn by_ref(&mut self) -> ByRef<'_, Self>where
Self: Sized,
fn by_ref(&mut self) -> ByRef<'_, Self>where
Self: Sized,
&mut Self
as a parser Read moreSourceยงfn default_value<O2>(self) -> DefaultValue<Self, I, O, O2, E>
fn default_value<O2>(self) -> DefaultValue<Self, I, O, O2, E>
Sourceยงfn void(self) -> Void<Self, I, O, E>where
Self: Sized,
fn void(self) -> Void<Self, I, O, E>where
Self: Sized,
Parser
Read moreSourceยงfn output_into<O2>(self) -> OutputInto<Self, I, O, O2, E>
fn output_into<O2>(self) -> OutputInto<Self, I, O, O2, E>
std::convert::From
Read moreSourceยงfn recognize(self) -> Take<Self, I, O, E>
fn recognize(self) -> Take<Self, I, O, E>
Parser::take
Parser::take
Sourceยงfn with_taken(self) -> WithTaken<Self, I, O, E>
fn with_taken(self) -> WithTaken<Self, I, O, E>
Sourceยงfn with_recognized(self) -> WithTaken<Self, I, O, E>
fn with_recognized(self) -> WithTaken<Self, I, O, E>
Parser::with_taken
Parser::with_taken
Sourceยงfn span(self) -> Span<Self, I, O, E>
fn span(self) -> Span<Self, I, O, E>
Sourceยงfn with_span(self) -> WithSpan<Self, I, O, E>
fn with_span(self) -> WithSpan<Self, I, O, E>
Sourceยงfn map<G, O2>(self, map: G) -> Map<Self, G, I, O, O2, E>
fn map<G, O2>(self, map: G) -> Map<Self, G, I, O, O2, E>
Sourceยงfn try_map<G, O2, E2>(self, map: G) -> TryMap<Self, G, I, O, O2, E, E2>
fn try_map<G, O2, E2>(self, map: G) -> TryMap<Self, G, I, O, O2, E, E2>
Result
over the output of a parser. Read moreSourceยงfn verify_map<G, O2>(self, map: G) -> VerifyMap<Self, G, I, O, O2, E>
fn verify_map<G, O2>(self, map: G) -> VerifyMap<Self, G, I, O, O2, E>
Sourceยงfn flat_map<G, H, O2>(self, map: G) -> FlatMap<Self, G, H, I, O, O2, E>
fn flat_map<G, H, O2>(self, map: G) -> FlatMap<Self, G, H, I, O, O2, E>
Sourceยงfn and_then<G, O2>(self, inner: G) -> AndThen<Self, G, I, O, O2, E>
fn and_then<G, O2>(self, inner: G) -> AndThen<Self, G, I, O, O2, E>
Sourceยงfn parse_to<O2>(self) -> ParseTo<Self, I, O, O2, E>
fn parse_to<O2>(self) -> ParseTo<Self, I, O, O2, E>
std::str::FromStr
to the output of the parser Read moreSourceยงfn verify<G, O2>(self, filter: G) -> Verify<Self, G, I, O, O2, E>
fn verify<G, O2>(self, filter: G) -> Verify<Self, G, I, O, O2, E>
Sourceยงfn context<C>(self, context: C) -> Context<Self, I, O, E, C>
fn context<C>(self, context: C) -> Context<Self, I, O, E, C>
Sourceยงfn complete_err(self) -> CompleteErr<Self>where
Self: Sized,
fn complete_err(self) -> CompleteErr<Self>where
Self: Sized,
Sourceยงimpl<F, T> Parser for F
impl<F, T> Parser for F
type Output = T
Sourceยงfn parse2(self, tokens: TokenStream) -> Result<T, Error>
fn parse2(self, tokens: TokenStream) -> Result<T, Error>
fn __parse_scoped( self, scope: Span, tokens: TokenStream, ) -> Result<<F as Parser>::Output, Error>
Sourceยงimpl<F> Pattern for F
impl<F> Pattern for F
Sourceยงtype Searcher<'a> = CharPredicateSearcher<'a, F>
type Searcher<'a> = CharPredicateSearcher<'a, F>
pattern
)Sourceยงfn into_searcher<'a>(self, haystack: &'a str) -> CharPredicateSearcher<'a, F>
fn into_searcher<'a>(self, haystack: &'a str) -> CharPredicateSearcher<'a, F>
pattern
)self
and the haystack
to search in.Sourceยงfn is_contained_in<'a>(self, haystack: &'a str) -> bool
fn is_contained_in<'a>(self, haystack: &'a str) -> bool
pattern
)Sourceยงfn is_prefix_of<'a>(self, haystack: &'a str) -> bool
fn is_prefix_of<'a>(self, haystack: &'a str) -> bool
pattern
)Sourceยงfn strip_prefix_of<'a>(self, haystack: &'a str) -> Option<&'a str>
fn strip_prefix_of<'a>(self, haystack: &'a str) -> Option<&'a str>
pattern
)Sourceยงfn is_suffix_of<'a>(self, haystack: &'a str) -> boolwhere
CharPredicateSearcher<'a, F>: ReverseSearcher<'a>,
fn is_suffix_of<'a>(self, haystack: &'a str) -> boolwhere
CharPredicateSearcher<'a, F>: ReverseSearcher<'a>,
pattern
)Sourceยงfn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&'a str>where
CharPredicateSearcher<'a, F>: ReverseSearcher<'a>,
fn strip_suffix_of<'a>(self, haystack: &'a str) -> Option<&'a str>where
CharPredicateSearcher<'a, F>: ReverseSearcher<'a>,
pattern
)Sourceยงfn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>>
fn as_utf8_pattern(&self) -> Option<Utf8Pattern<'_>>
pattern
)Sourceยงimpl<T> Pointable for T
impl<T> Pointable for T
Sourceยงimpl<F, T> Replacer for F
impl<F, T> Replacer for F
Sourceยงfn replace_append(&mut self, caps: &Captures<'_>, dst: &mut Vec<u8>)
fn replace_append(&mut self, caps: &Captures<'_>, dst: &mut Vec<u8>)
dst
to replace the current match. Read moreSourceยงfn no_expansion<'r>(&'r mut self) -> Option<Cow<'r, [u8]>>
fn no_expansion<'r>(&'r mut self) -> Option<Cow<'r, [u8]>>
Sourceยงfn by_ref<'r>(&'r mut self) -> ReplacerRef<'r, Self>
fn by_ref<'r>(&'r mut self) -> ReplacerRef<'r, Self>
Sourceยงimpl<F, T> Replacer for F
impl<F, T> Replacer for F
Sourceยงfn replace_append(&mut self, caps: &Captures<'_>, dst: &mut String)
fn replace_append(&mut self, caps: &Captures<'_>, dst: &mut String)
dst
to replace the current match. Read moreSourceยงfn no_expansion<'r>(&'r mut self) -> Option<Cow<'r, str>>
fn no_expansion<'r>(&'r mut self) -> Option<Cow<'r, str>>
Sourceยงfn by_ref<'r>(&'r mut self) -> ReplacerRef<'r, Self>
fn by_ref<'r>(&'r mut self) -> ReplacerRef<'r, Self>
Sourceยงimpl<Fut> TryFutureExt for Fut
impl<Fut> TryFutureExt for Fut
Sourceยงfn flatten_sink<Item>(self) -> FlattenSink<Self, Self::Ok>
fn flatten_sink<Item>(self) -> FlattenSink<Self, Self::Ok>
Sourceยงfn map_ok<T, F>(self, f: F) -> MapOk<Self, F> โ
fn map_ok<T, F>(self, f: F) -> MapOk<Self, F> โ
Sourceยงfn map_ok_or_else<T, E, F>(self, e: E, f: F) -> MapOkOrElse<Self, F, E> โ
fn map_ok_or_else<T, E, F>(self, e: E, f: F) -> MapOkOrElse<Self, F, E> โ
Sourceยงfn map_err<E, F>(self, f: F) -> MapErr<Self, F> โ
fn map_err<E, F>(self, f: F) -> MapErr<Self, F> โ
Sourceยงfn and_then<Fut, F>(self, f: F) -> AndThen<Self, Fut, F> โ
fn and_then<Fut, F>(self, f: F) -> AndThen<Self, Fut, F> โ
Sourceยงfn or_else<Fut, F>(self, f: F) -> OrElse<Self, Fut, F> โ
fn or_else<Fut, F>(self, f: F) -> OrElse<Self, Fut, F> โ
Sourceยงfn inspect_ok<F>(self, f: F) -> InspectOk<Self, F> โ
fn inspect_ok<F>(self, f: F) -> InspectOk<Self, F> โ
Sourceยงfn inspect_err<F>(self, f: F) -> InspectErr<Self, F> โ
fn inspect_err<F>(self, f: F) -> InspectErr<Self, F> โ
Sourceยงfn try_flatten(self) -> TryFlatten<Self, Self::Ok> โ
fn try_flatten(self) -> TryFlatten<Self, Self::Ok> โ
Sourceยงfn try_flatten_stream(self) -> TryFlattenStream<Self>
fn try_flatten_stream(self) -> TryFlattenStream<Self>
Sourceยงfn unwrap_or_else<F>(self, f: F) -> UnwrapOrElse<Self, F> โ
fn unwrap_or_else<F>(self, f: F) -> UnwrapOrElse<Self, F> โ
Sourceยงfn into_future(self) -> IntoFuture<Self> โwhere
Self: Sized,
fn into_future(self) -> IntoFuture<Self> โwhere
Self: Sized,
Sourceยงimpl<F> Visit for F
impl<F> Visit for F
Sourceยงfn record_debug(&mut self, field: &Field, value: &dyn Debug)
fn record_debug(&mut self, field: &Field, value: &dyn Debug)
fmt::Debug
.