pub struct SyncView<T>where
T: ?Sized,{ /* private fields */ }exclusive_wrapper)Expand description
SyncView provides mutable access, also referred to as exclusive
access to the underlying value. However, it only permits immutable, or shared
access to the underlying value when that value is Sync.
While this may seem not very useful, it allows SyncView to unconditionally
implement Sync. Indeed, the safety requirements of Sync state that for SyncView
to be Sync, it must be sound to share across threads, that is, it must be sound
for &SyncView to cross thread boundaries. By design, a &SyncView<T> for non-Sync
T has no API whatsoever, making it useless, thus harmless, thus memory safe.
Certain constructs like Futures can only be used with exclusive access,
and are often Send but not Sync, so SyncView 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();
}
});SyncView ensures the struct is Sync without stripping the future of its
functionality:
#![feature(exclusive_wrapper)]
use core::cell::Cell;
use core::sync::SyncView;
async fn other() {}
fn assert_sync<T: Sync>(t: T) {}
struct State<F> {
future: SyncView<F>
}
assert_sync(State {
future: SyncView::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, SyncView 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> SyncView<T>where
T: ?Sized,
impl<T> SyncView<T>where
T: ?Sized,
Sourcepub const fn as_pin_mut(self: Pin<&mut SyncView<T>>) -> Pin<&mut T>
🔬This is a nightly-only experimental API. (exclusive_wrapper)
pub const fn as_pin_mut(self: Pin<&mut SyncView<T>>) -> Pin<&mut T>
exclusive_wrapper)Gets pinned exclusive access to the underlying value.
SyncView is considered to structurally pin the underlying
value, which means unpinned SyncViews can produce unpinned
access to the underlying value, but pinned SyncViews only
produce pinned access to the underlying value.
Sourcepub const fn from_mut(r: &mut T) -> &mut SyncView<T> ⓘ
🔬This is a nightly-only experimental API. (exclusive_wrapper)
pub const fn from_mut(r: &mut T) -> &mut SyncView<T> ⓘ
exclusive_wrapper)Build a mutable reference to an SyncView<T> from
a mutable reference to a T. This allows you to skip
building an SyncView with SyncView::new.
Sourcepub const fn from_pin_mut(r: Pin<&mut T>) -> Pin<&mut SyncView<T>>
🔬This is a nightly-only experimental API. (exclusive_wrapper)
pub const fn from_pin_mut(r: Pin<&mut T>) -> Pin<&mut SyncView<T>>
exclusive_wrapper)Build a pinned mutable reference to an SyncView<T> from
a pinned mutable reference to a T. This allows you to skip
building an SyncView with SyncView::new.
Source§impl<T> SyncView<T>
impl<T> SyncView<T>
Sourcepub const fn as_pin(self: Pin<&SyncView<T>>) -> Pin<&T>
🔬This is a nightly-only experimental API. (exclusive_wrapper)
pub const fn as_pin(self: Pin<&SyncView<T>>) -> Pin<&T>
exclusive_wrapper)Gets pinned shared access to the underlying value.
SyncView is considered to structurally pin the underlying
value, which means unpinned SyncViews can produce unpinned
access to the underlying value, but pinned SyncViews only
produce pinned access to the underlying value.
Trait Implementations§
Source§impl<F, Args> AsyncFn<Args> for SyncView<F>
impl<F, Args> AsyncFn<Args> for SyncView<F>
Source§extern "rust-call" fn async_call(
&self,
args: Args,
) -> <SyncView<F> as AsyncFnMut<Args>>::CallRefFuture<'_> ⓘ
extern "rust-call" fn async_call( &self, args: Args, ) -> <SyncView<F> as AsyncFnMut<Args>>::CallRefFuture<'_> ⓘ
async_fn_traits)AsyncFn, returning a future which may borrow from the called closure.Source§impl<F, Args> AsyncFnMut<Args> for SyncView<F>where
F: AsyncFnMut<Args>,
Args: Tuple,
impl<F, Args> AsyncFnMut<Args> for SyncView<F>where
F: AsyncFnMut<Args>,
Args: Tuple,
Source§type CallRefFuture<'a> = <F as AsyncFnMut<Args>>::CallRefFuture<'a>
where
F: 'a
type CallRefFuture<'a> = <F as AsyncFnMut<Args>>::CallRefFuture<'a> where F: 'a
async_fn_traits)AsyncFnMut::async_call_mut and AsyncFn::async_call.Source§extern "rust-call" fn async_call_mut(
&mut self,
args: Args,
) -> <SyncView<F> as AsyncFnMut<Args>>::CallRefFuture<'_> ⓘ
extern "rust-call" fn async_call_mut( &mut self, args: Args, ) -> <SyncView<F> as AsyncFnMut<Args>>::CallRefFuture<'_> ⓘ
async_fn_traits)AsyncFnMut, returning a future which may borrow from the called closure.Source§impl<F, Args> AsyncFnOnce<Args> for SyncView<F>where
F: AsyncFnOnce<Args>,
Args: Tuple,
impl<F, Args> AsyncFnOnce<Args> for SyncView<F>where
F: AsyncFnOnce<Args>,
Args: Tuple,
Source§type CallOnceFuture = <F as AsyncFnOnce<Args>>::CallOnceFuture
type CallOnceFuture = <F as AsyncFnOnce<Args>>::CallOnceFuture
async_fn_traits)AsyncFnOnce::async_call_once.Source§type Output = <F as AsyncFnOnce<Args>>::Output
type Output = <F as AsyncFnOnce<Args>>::Output
async_fn_traits)Source§extern "rust-call" fn async_call_once(
self,
args: Args,
) -> <SyncView<F> as AsyncFnOnce<Args>>::CallOnceFuture ⓘ
extern "rust-call" fn async_call_once( self, args: Args, ) -> <SyncView<F> as AsyncFnOnce<Args>>::CallOnceFuture ⓘ
async_fn_traits)AsyncFnOnce, returning a future which may move out of the called closure.Source§impl<R, G> Coroutine<R> for SyncView<G>
impl<R, G> Coroutine<R> for SyncView<G>
Source§type Yield = <G as Coroutine<R>>::Yield
type Yield = <G as Coroutine<R>>::Yield
coroutine_trait)Source§impl<T> Ord for SyncView<T>
impl<T> Ord for SyncView<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T, U> PartialOrd<SyncView<U>> for SyncView<T>
impl<T, U> PartialOrd<SyncView<U>> for SyncView<T>
impl<T> Copy for SyncView<T>
impl<T> Eq for SyncView<T>
impl<T> StructuralPartialEq for SyncView<T>
impl<T> Sync for SyncView<T>where
T: ?Sized,
Auto Trait Implementations§
impl<T> Freeze for SyncView<T>
impl<T> RefUnwindSafe for SyncView<T>where
T: RefUnwindSafe + ?Sized,
impl<T> Send for SyncView<T>
impl<T> Unpin for SyncView<T>
impl<T> UnsafeUnpin for SyncView<T>where
T: UnsafeUnpin + ?Sized,
impl<T> UnwindSafe for SyncView<T>where
T: UnwindSafe + ?Sized,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C, F> ContainsToken<C> for F
impl<C, F> ContainsToken<C> for F
§fn contains_token(&self, token: C) -> bool
fn contains_token(&self, token: C) -> bool
§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<F, N> FidlIntoNative<Box<N>> for Fwhere
F: FidlIntoNative<N>,
impl<F, N> FidlIntoNative<Box<N>> for Fwhere
F: FidlIntoNative<N>,
fn fidl_into_native(self) -> Box<N>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn map<U, F>(self, f: F) -> Map<Self, F> ⓘ
fn map<U, F>(self, f: F) -> Map<Self, F> ⓘ
§fn map_into<U>(self) -> MapInto<Self, U> ⓘ
fn map_into<U>(self) -> MapInto<Self, U> ⓘ
§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F> ⓘ
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F> ⓘ
f. Read more§fn left_future<B>(self) -> Either<Self, B> ⓘ
fn left_future<B>(self) -> Either<Self, B> ⓘ
§fn right_future<A>(self) -> Either<A, Self> ⓘ
fn right_future<A>(self) -> Either<A, Self> ⓘ
§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
§fn flatten(self) -> Flatten<Self> ⓘ
fn flatten(self) -> Flatten<Self> ⓘ
§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
§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 more§fn inspect<F>(self, f: F) -> Inspect<Self, F> ⓘ
fn inspect<F>(self, f: F) -> Inspect<Self, F> ⓘ
§fn catch_unwind(self) -> CatchUnwind<Self> ⓘwhere
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self> ⓘwhere
Self: Sized + UnwindSafe,
§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 more§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>>
§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,
§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 = ()>.§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> 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<T, U> MultiArchFrom<T> for Uwhere
U: From<T>,
impl<T, U> MultiArchFrom<T> for Uwhere
U: From<T>,
§impl<I, O, E, F> Parser<I, O, E> for F
impl<I, O, E, F> Parser<I, O, E> for F
§fn parse_next(&mut self, i: &mut I) -> Result<O, E>
fn parse_next(&mut self, i: &mut I) -> Result<O, E>
Stream], turning it into the output Read more§fn parse(
&mut self,
input: I,
) -> Result<O, ParseError<I, <E as ParserError<I>>::Inner>>where
Self: Sized,
I: Stream + StreamIsPartial,
E: ParserError<I>,
<E as ParserError<I>>::Inner: ParserError<I>,
fn parse(
&mut self,
input: I,
) -> Result<O, ParseError<I, <E as ParserError<I>>::Inner>>where
Self: Sized,
I: Stream + StreamIsPartial,
E: ParserError<I>,
<E as ParserError<I>>::Inner: ParserError<I>,
§fn parse_peek(&mut self, input: I) -> Result<(I, O), E>
fn parse_peek(&mut self, input: I) -> Result<(I, O), E>
Stream], turning it into the output Read more§fn by_ref(&mut self) -> ByRef<'_, Self, I, O, E>where
Self: Sized,
fn by_ref(&mut self) -> ByRef<'_, Self, I, O, E>where
Self: Sized,
&mut Self as a parser Read more§fn default_value<O2>(self) -> DefaultValue<Self, I, O, O2, E>
fn default_value<O2>(self) -> DefaultValue<Self, I, O, O2, E>
§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 more§fn take(self) -> Take<Self, I, O, E>where
Self: Sized,
I: Stream,
fn take(self) -> Take<Self, I, O, E>where
Self: Sized,
I: Stream,
§fn with_taken(self) -> WithTaken<Self, I, O, E>where
Self: Sized,
I: Stream,
fn with_taken(self) -> WithTaken<Self, I, O, E>where
Self: Sized,
I: Stream,
§fn span(self) -> Span<Self, I, O, E>where
Self: Sized,
I: Stream + Location,
fn span(self) -> Span<Self, I, O, E>where
Self: Sized,
I: Stream + Location,
§fn with_span(self) -> WithSpan<Self, I, O, E>where
Self: Sized,
I: Stream + Location,
fn with_span(self) -> WithSpan<Self, I, O, E>where
Self: Sized,
I: Stream + Location,
§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>
§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 more§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>
§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>
§fn and_then<G, O2>(self, inner: G) -> AndThen<Self, G, I, O, O2, E>where
Self: Sized,
G: Parser<O, O2, E>,
O: StreamIsPartial,
I: Stream,
fn and_then<G, O2>(self, inner: G) -> AndThen<Self, G, I, O, O2, E>where
Self: Sized,
G: Parser<O, O2, E>,
O: StreamIsPartial,
I: Stream,
§fn parse_to<O2>(self) -> ParseTo<Self, I, O, O2, E>where
Self: Sized,
I: Stream,
O: ParseSlice<O2>,
E: ParserError<I>,
fn parse_to<O2>(self) -> ParseTo<Self, I, O, O2, E>where
Self: Sized,
I: Stream,
O: ParseSlice<O2>,
E: ParserError<I>,
std::str::FromStr to the output of the parser Read more§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>
§fn context<C>(self, context: C) -> Context<Self, I, O, E, C>
fn context<C>(self, context: C) -> Context<Self, I, O, E, C>
§fn context_with<F, C, FI>(
self,
context: F,
) -> ContextWith<Self, I, O, E, F, C, FI>
fn context_with<F, C, FI>( self, context: F, ) -> ContextWith<Self, I, O, E, F, C, FI>
§fn map_err<G, E2>(self, map: G) -> MapErr<Self, G, I, O, E, E2>
fn map_err<G, E2>(self, map: G) -> MapErr<Self, G, I, O, E, E2>
§fn complete_err(self) -> CompleteErr<Self, I, O, E>where
Self: Sized,
fn complete_err(self) -> CompleteErr<Self, I, O, E>where
Self: Sized,
Incomplete][crate::error::ErrMode::Incomplete] into [Backtrack][crate::error::ErrMode::Backtrack] Read more§fn err_into<E2>(self) -> ErrInto<Self, I, O, E, E2>
fn err_into<E2>(self) -> ErrInto<Self, I, O, E, E2>
std::convert::FromSource§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)§impl<T> Pointable for T
impl<T> Pointable for T
§impl<F> TimeoutExt for Fwhere
F: Future,
impl<F> TimeoutExt for Fwhere
F: Future,
§fn on_timeout<WT, OT>(self, time: WT, on_timeout: OT) -> OnTimeout<Self, OT> ⓘ
fn on_timeout<WT, OT>(self, time: WT, on_timeout: OT) -> OnTimeout<Self, OT> ⓘ
on_timeout to produce a result
when the timeout occurs.§fn on_stalled<OS>(
self,
timeout: Duration,
on_stalled: OS,
) -> OnStalled<Self, OS> ⓘ
fn on_stalled<OS>( self, timeout: Duration, on_stalled: OS, ) -> OnStalled<Self, OS> ⓘ
on_stalled to produce a result
when the future hasn’t been otherwise polled within the timeout.
This is a heuristic - spurious wakeups will keep the detection from triggering,
and moving all work to external tasks or threads with force the triggering early.§impl<F, T, E> TryFuture for F
impl<F, T, E> TryFuture for F
§impl<Fut> TryFutureExt for Futwhere
Fut: TryFuture + ?Sized,
impl<Fut> TryFutureExt for Futwhere
Fut: TryFuture + ?Sized,
§fn flatten_sink<Item>(self) -> FlattenSink<Self, Self::Ok>where
Self::Ok: Sink<Item, Error = Self::Error>,
Self: Sized,
fn flatten_sink<Item>(self) -> FlattenSink<Self, Self::Ok>where
Self::Ok: Sink<Item, Error = Self::Error>,
Self: Sized,
Sink]. Read more