pub trait Collection {
type Idx;
type Output: ?Sized;
type ShadowLocks: ShadowLocksCollection<Idx = Self::Idx>;
type ShadowLocksAsync: ShadowLocksCollectionAsync<Idx = Self::Idx>;
// Required methods
fn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>;
fn index_mut(
&mut self,
index: impl Borrow<Self::Idx>,
) -> Option<&mut Self::Output>;
fn indices(&self) -> impl Iterator<Item = Self::Idx>;
fn shadow_locks(&self) -> Self::ShadowLocks;
fn shadow_locks_async(&self) -> Self::ShadowLocksAsync;
}Expand description
Trait describes functionality of collection that necessary for creating LockerRoom
and LockerRoomAsync.
Required Associated Types§
Sourcetype ShadowLocks: ShadowLocksCollection<Idx = Self::Idx>
type ShadowLocks: ShadowLocksCollection<Idx = Self::Idx>
Type of collection which stores RwLocks. Usually the same type as Collection’s implementor.
It’s necessary because of performance. For example, implementing Collection for Vec but using BTreeMap as ShadowLocks makes little sense
because LockerRoom at every index (or index_mut) method call will also call the
same method of ShadowLocks. This makes meaningless to use Vec because its performance will be bottlenecked by BTreeMap.
Sourcetype ShadowLocksAsync: ShadowLocksCollectionAsync<Idx = Self::Idx>
Available on crate feature async only.
type ShadowLocksAsync: ShadowLocksCollectionAsync<Idx = Self::Idx>
async only.Similar to ShadowLocks but stores tokio’s RwLocks.
Used in LockerRoomAsync.
Required Methods§
Sourcefn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>
fn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>
Performs the indexing operation. But unlike the Index::index, it doesn’t panic, and return None.
Sourcefn index_mut(
&mut self,
index: impl Borrow<Self::Idx>,
) -> Option<&mut Self::Output>
fn index_mut( &mut self, index: impl Borrow<Self::Idx>, ) -> Option<&mut Self::Output>
Performs the mutable indexing operation. But unlike the IndexMut::index_mut, it doesn’t panic, and return None.
Sourcefn shadow_locks(&self) -> Self::ShadowLocks
fn shadow_locks(&self) -> Self::ShadowLocks
Creates collection which stores RwLocks.
Used in LockerRoom.
Sourcefn shadow_locks_async(&self) -> Self::ShadowLocksAsync
Available on crate feature async only.
fn shadow_locks_async(&self) -> Self::ShadowLocksAsync
async only.Creates collection wich stores tokio’s RwLocks.
Used in LockerRoomAsync.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<K, V> Collection for BTreeMap<K, V>
impl<K, V> Collection for BTreeMap<K, V>
type Idx = K
type Output = V
type ShadowLocks = BTreeMap<<BTreeMap<K, V> as Collection>::Idx, RwLock<()>>
Source§type ShadowLocksAsync = BTreeMap<<BTreeMap<K, V> as Collection>::Idx, RwLock<()>>
type ShadowLocksAsync = BTreeMap<<BTreeMap<K, V> as Collection>::Idx, RwLock<()>>
async only.fn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>
fn index_mut( &mut self, index: impl Borrow<Self::Idx>, ) -> Option<&mut Self::Output>
fn indices(&self) -> impl Iterator<Item = Self::Idx>
fn shadow_locks(&self) -> Self::ShadowLocks
Source§fn shadow_locks_async(&self) -> Self::ShadowLocksAsync
fn shadow_locks_async(&self) -> Self::ShadowLocksAsync
async only.Source§impl<K, V> Collection for HashMap<K, V>
impl<K, V> Collection for HashMap<K, V>
type Idx = K
type Output = V
type ShadowLocks = HashMap<<HashMap<K, V> as Collection>::Idx, RwLock<()>>
Source§type ShadowLocksAsync = HashMap<<HashMap<K, V> as Collection>::Idx, RwLock<()>>
type ShadowLocksAsync = HashMap<<HashMap<K, V> as Collection>::Idx, RwLock<()>>
async only.fn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>
fn index_mut( &mut self, index: impl Borrow<Self::Idx>, ) -> Option<&mut Self::Output>
fn indices(&self) -> impl Iterator<Item = Self::Idx>
fn shadow_locks(&self) -> Self::ShadowLocks
Source§fn shadow_locks_async(&self) -> Self::ShadowLocksAsync
fn shadow_locks_async(&self) -> Self::ShadowLocksAsync
async only.Source§impl<T> Collection for [T]
impl<T> Collection for [T]
type Idx = usize
type Output = T
type ShadowLocks = Vec<RwLock<()>>
fn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>
fn index_mut( &mut self, index: impl Borrow<Self::Idx>, ) -> Option<&mut Self::Output>
fn indices(&self) -> impl Iterator<Item = Self::Idx>
fn shadow_locks(&self) -> Self::ShadowLocks
Source§fn shadow_locks_async(&self) -> Self::ShadowLocksAsync
fn shadow_locks_async(&self) -> Self::ShadowLocksAsync
async only.Source§impl<T> Collection for VecDeque<T>
impl<T> Collection for VecDeque<T>
type Idx = usize
type Output = T
type ShadowLocks = VecDeque<RwLock<()>>
fn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>
fn index_mut( &mut self, index: impl Borrow<Self::Idx>, ) -> Option<&mut Self::Output>
fn indices(&self) -> impl Iterator<Item = Self::Idx>
fn shadow_locks(&self) -> Self::ShadowLocks
Source§fn shadow_locks_async(&self) -> Self::ShadowLocksAsync
fn shadow_locks_async(&self) -> Self::ShadowLocksAsync
async only.Source§impl<T> Collection for Vec<T>
impl<T> Collection for Vec<T>
type Idx = usize
type Output = T
type ShadowLocks = Vec<RwLock<()>>
fn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>
fn index_mut( &mut self, index: impl Borrow<Self::Idx>, ) -> Option<&mut Self::Output>
fn indices(&self) -> impl Iterator<Item = Self::Idx>
fn shadow_locks(&self) -> Self::ShadowLocks
Source§fn shadow_locks_async(&self) -> Self::ShadowLocksAsync
fn shadow_locks_async(&self) -> Self::ShadowLocksAsync
async only.Source§impl<T, const N: usize> Collection for [T; N]
impl<T, const N: usize> Collection for [T; N]
type Idx = usize
type Output = T
type ShadowLocks = Vec<RwLock<()>>
fn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>
fn index_mut( &mut self, index: impl Borrow<Self::Idx>, ) -> Option<&mut Self::Output>
fn indices(&self) -> impl Iterator<Item = Self::Idx>
fn shadow_locks(&self) -> Self::ShadowLocks
Source§fn shadow_locks_async(&self) -> Self::ShadowLocksAsync
fn shadow_locks_async(&self) -> Self::ShadowLocksAsync
async only.