Trait frame_support::dispatch::marker::Sync 1.0.0[−][src]
pub unsafe auto trait Sync { }Expand description
Types for which it is safe to share references between threads.
This trait is automatically implemented when the compiler determines it’s appropriate.
The precise definition is: a type T is Sync if and only if &T is
Send. In other words, if there is no possibility of
undefined behavior (including data races) when passing
&T references between threads.
As one would expect, primitive types like u8 and f64
are all Sync, and so are simple aggregate types containing them,
like tuples, structs and enums. More examples of basic Sync
types include “immutable” types like &T, and those with simple
inherited mutability, such as Box<T>, Vec<T> and
most other collection types. (Generic parameters need to be Sync
for their container to be Sync.)
A somewhat surprising consequence of the definition is that &mut T
is Sync (if T is Sync) even though it seems like that might
provide unsynchronized mutation. The trick is that a mutable
reference behind a shared reference (that is, & &mut T)
becomes read-only, as if it were a & &T. Hence there is no risk
of a data race.
Types that are not Sync are those that have “interior
mutability” in a non-thread-safe form, such as Cell
and RefCell. These types allow for mutation of
their contents even through an immutable, shared reference. For
example the set method on Cell<T> takes &self, so it requires
only a shared reference &Cell<T>. The method performs no
synchronization, thus Cell cannot be Sync.
Another example of a non-Sync type is the reference-counting
pointer Rc. Given any reference &Rc<T>, you can clone
a new Rc<T>, modifying the reference counts in a non-atomic way.
For cases when one does need thread-safe interior mutability,
Rust provides atomic data types, as well as explicit locking via
sync::Mutex and sync::RwLock. These types
ensure that any mutation cannot cause data races, hence the types
are Sync. Likewise, sync::Arc provides a thread-safe
analogue of Rc.
Any types with interior mutability must also use the
cell::UnsafeCell wrapper around the value(s) which
can be mutated through a shared reference. Failing to doing this is
undefined behavior. For example, transmute-ing
from &T to &mut T is invalid.
See the Nomicon for more details about Sync.
Implementations on Foreign Types
impl Sync for Argumentimpl Sync for FormatSpecimpl Sync for Alignmentimpl Sync for CountNonNull pointers are not Sync because the data they reference may be aliased.
impl<'a, R, T> Sync for MappedRwLockReadGuard<'a, R, T> where
T: 'a + Sync + ?Sized,
R: 'a + RawRwLock, impl<'a, R, T> Sync for MappedRwLockWriteGuard<'a, R, T> where
T: 'a + Sync + ?Sized,
R: 'a + RawRwLock, impl<'a, R, T> Sync for RwLockUpgradableReadGuard<'a, R, T> where
T: 'a + Sync + ?Sized,
R: 'a + RawRwLockUpgrade, impl<R, G, T> Sync for ReentrantMutex<R, G, T> where
T: Send + ?Sized,
R: RawMutex + Sync,
G: GetThreadId + Sync, impl<'a, R, G, T> Sync for MappedReentrantMutexGuard<'a, R, G, T> where
T: 'a + Sync + ?Sized,
R: 'a + RawMutex + Sync,
G: 'a + GetThreadId + Sync, impl<'a, R, T> Sync for MappedMutexGuard<'a, R, T> where
T: 'a + Sync + ?Sized,
R: 'a + RawMutex + Sync, impl<'a, R, G, T> Sync for ReentrantMutexGuard<'a, R, G, T> where
T: 'a + Sync + ?Sized,
R: 'a + RawMutex + Sync,
G: 'a + GetThreadId + Sync, impl Sync for GuardNoSendimpl<'_, K, V, S, A> Sync for RawOccupiedEntryMut<'_, K, V, S, A> where
A: Send + Allocator + Clone,
K: Sync,
V: Sync, impl<'_, K, V, S, A> Sync for OccupiedEntry<'_, K, V, S, A> where
A: Sync + Allocator + Clone,
K: Sync,
V: Sync,
S: Sync, impl Sync for AtomicWakerImplementors
Auto implementors
impl Sync for DispatchErrorimpl Sync for InvalidTransactionimpl Sync for TransactionSourceimpl Sync for TransactionValidityErrorimpl Sync for UnknownTransactionimpl Sync for KillStorageResultimpl Sync for Everythingimpl Sync for BalanceStatusimpl Sync for DepositConsequenceimpl Sync for ExistenceRequirementimpl Sync for DispatchClassimpl Sync for FrameTransactionPriorityimpl Sync for EventMetadataimpl Sync for OuterEventMetadataimpl Sync for CheckInherentsResultimpl Sync for Instance10impl Sync for Instance11impl Sync for Instance12impl Sync for Instance13impl Sync for Instance14impl Sync for Instance15impl Sync for Instance16impl Sync for Blake2_128impl Sync for Blake2_128Concatimpl Sync for Blake2_256impl Sync for InherentDataimpl Sync for Twox64Concatimpl Sync for ValidTransactionimpl Sync for OptionQueryimpl Sync for ValueQueryimpl Sync for GetDefaultimpl Sync for SaturatingCurrencyToVoteimpl Sync for StorageInfoimpl Sync for StorageVersionimpl Sync for U128CurrencyToVoteimpl Sync for WithdrawReasonsimpl Sync for BlockExecutionWeightimpl Sync for ExtrinsicBaseWeightimpl Sync for ParityDbWeightimpl Sync for RocksDbWeightimpl Sync for DispatchInfoimpl Sync for PostDispatchInfoimpl Sync for RuntimeDbWeightimpl Sync for CallMetadataimpl Sync for DefaultByteGetterimpl Sync for ErrorMetadataimpl Sync for FunctionArgumentMetadataimpl Sync for FunctionMetadataimpl Sync for ModuleConstantMetadataimpl Sync for PhantomPinnedimpl<'a, 'b> !Sync for DebugStruct<'a, 'b>impl<'a, 'b> !Sync for DebugTuple<'a, 'b>impl<'a, T, S> Sync for BoundedSlice<'a, T, S> where
S: Sync,
T: Sync, impl<A, B> Sync for SameOrOther<A, B> where
A: Sync,
B: Sync, impl<A, B, OnDrop, OppositeOnDrop> Sync for frame_support::traits::tokens::fungibles::Imbalance<A, B, OnDrop, OppositeOnDrop> where
A: Sync,
B: Sync,
OnDrop: Sync,
OppositeOnDrop: Sync, impl<B, O> Sync for DecodeDifferent<B, O> where
B: Sync,
O: Sync, impl<B, OnDrop, OppositeOnDrop> Sync for frame_support::traits::tokens::fungible::Imbalance<B, OnDrop, OppositeOnDrop> where
B: Sync,
OnDrop: Sync,
OppositeOnDrop: Sync, impl<B, PositiveImbalance> Sync for SignedImbalance<B, PositiveImbalance> where
PositiveImbalance: Sync,
<PositiveImbalance as Imbalance<B>>::Opposite: Sync, impl<Balance> Sync for WithdrawConsequence<Balance> where
Balance: Sync, impl<Balance> Sync for WeightToFeeCoefficient<Balance> where
Balance: Sync, impl<Balance, Imbalance, Part1, Target1, Part2, Target2> Sync for SplitTwoWays<Balance, Imbalance, Part1, Target1, Part2, Target2> where
Balance: Sync,
Imbalance: Sync,
Part1: Sync,
Part2: Sync,
Target1: Sync,
Target2: Sync, impl<BlockNumber> Sync for DispatchTime<BlockNumber> where
BlockNumber: Sync, impl<E> Sync for MakeFatalError<E> where
E: Sync, impl<F, A, AccountId> Sync for frame_support::traits::tokens::fungible::ItemOf<F, A, AccountId> where
A: Sync,
AccountId: Sync,
F: Sync, impl<F, A, AccountId> Sync for frame_support::traits::tokens::nonfungible::ItemOf<F, A, AccountId> where
A: Sync,
AccountId: Sync,
F: Sync, impl<F, T> Sync for ClearFilterGuard<F, T> where
T: Sync,
<F as FilterStack<T>>::Stack: Sync, impl<F, T> Sync for FilterStackGuard<F, T> where
F: Sync,
T: Sync, impl<Hasher, KeyType> Sync for frame_support::storage::types::Key<Hasher, KeyType> where
Hasher: Sync,
KeyType: Sync, impl<K, T, H> Sync for StorageKeyIterator<K, T, H> where
H: Sync,
K: Sync,
T: Sync, impl<K, V, S> Sync for BoundedBTreeMap<K, V, S> where
K: Sync,
S: Sync,
V: Sync, impl<OM> Sync for AsContains<OM> where
OM: Sync, impl<Prefix, Hasher1, Key1, Hasher2, Key2, Value, QueryKind, OnEmpty, MaxValues> Sync for StorageDoubleMap<Prefix, Hasher1, Key1, Hasher2, Key2, Value, QueryKind, OnEmpty, MaxValues> where
Hasher1: Sync,
Hasher2: Sync,
Key1: Sync,
Key2: Sync,
MaxValues: Sync,
OnEmpty: Sync,
Prefix: Sync,
QueryKind: Sync,
Value: Sync, impl<Prefix, Hasher, Key, Value, QueryKind, OnEmpty, MaxValues> Sync for StorageMap<Prefix, Hasher, Key, Value, QueryKind, OnEmpty, MaxValues> where
Hasher: Sync,
Key: Sync,
MaxValues: Sync,
OnEmpty: Sync,
Prefix: Sync,
QueryKind: Sync,
Value: Sync, impl<Prefix, Key, Value, QueryKind, OnEmpty, MaxValues> Sync for StorageNMap<Prefix, Key, Value, QueryKind, OnEmpty, MaxValues> where
Key: Sync,
MaxValues: Sync,
OnEmpty: Sync,
Prefix: Sync,
QueryKind: Sync,
Value: Sync, impl<Prefix, Value, QueryKind, OnEmpty> Sync for StorageValue<Prefix, Value, QueryKind, OnEmpty> where
OnEmpty: Sync,
Prefix: Sync,
QueryKind: Sync,
Value: Sync, impl<R> Sync for TransactionOutcome<R> where
R: Sync, impl<T> Sync for StorageIterator<T> where
T: Sync, impl<T> Sync for ChildTriePrefixIterator<T>impl<T> Sync for KeyPrefixIterator<T>impl<T> Sync for PrefixIterator<T>impl<T> Sync for IdentityFee<T> where
T: Sync, impl<T> Sync for PerDispatchClass<T> where
T: Sync, impl<T, S> Sync for BoundedBTreeSet<T, S> where
S: Sync,
T: Sync, impl<T, S> Sync for BoundedVec<T, S> where
S: Sync,
T: Sync, impl<T, S> Sync for WeakBoundedVec<T, S> where
S: Sync,
T: Sync, impl<T: ?Sized> Sync for PhantomData<T> where
T: Sync, impl<WD, CD, PF> Sync for FunctionOf<WD, CD, PF> where
CD: Sync,
PF: Sync,
WD: Sync,