Collection

Trait Collection 

Source
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§

Source

type Idx

Type that should be used as index

Source

type Output: ?Sized

The returned type after indexing.

Source

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.

Source

type ShadowLocksAsync: ShadowLocksCollectionAsync<Idx = Self::Idx>

Available on crate feature async only.

Similar to ShadowLocks but stores tokio’s RwLocks.

Used in LockerRoomAsync.

Required Methods§

Source

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.

Source

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.

Source

fn indices(&self) -> impl Iterator<Item = Self::Idx>

An iterator visiting all indices.

Source

fn shadow_locks(&self) -> Self::ShadowLocks

Creates collection which stores RwLocks.

Used in LockerRoom.

Source

fn shadow_locks_async(&self) -> Self::ShadowLocksAsync

Available on crate feature 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>
where K: Ord + Clone + ?Sized,

Source§

type Idx = K

Source§

type Output = V

Source§

type ShadowLocks = BTreeMap<<BTreeMap<K, V> as Collection>::Idx, RwLock<()>>

Source§

type ShadowLocksAsync = BTreeMap<<BTreeMap<K, V> as Collection>::Idx, RwLock<()>>

Available on crate feature async only.
Source§

fn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>

Source§

fn index_mut( &mut self, index: impl Borrow<Self::Idx>, ) -> Option<&mut Self::Output>

Source§

fn indices(&self) -> impl Iterator<Item = Self::Idx>

Source§

fn shadow_locks(&self) -> Self::ShadowLocks

Source§

fn shadow_locks_async(&self) -> Self::ShadowLocksAsync

Available on crate feature async only.
Source§

impl<K, V> Collection for HashMap<K, V>
where K: Eq + Hash + Clone + ?Sized,

Source§

type Idx = K

Source§

type Output = V

Source§

type ShadowLocks = HashMap<<HashMap<K, V> as Collection>::Idx, RwLock<()>>

Source§

type ShadowLocksAsync = HashMap<<HashMap<K, V> as Collection>::Idx, RwLock<()>>

Available on crate feature async only.
Source§

fn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>

Source§

fn index_mut( &mut self, index: impl Borrow<Self::Idx>, ) -> Option<&mut Self::Output>

Source§

fn indices(&self) -> impl Iterator<Item = Self::Idx>

Source§

fn shadow_locks(&self) -> Self::ShadowLocks

Source§

fn shadow_locks_async(&self) -> Self::ShadowLocksAsync

Available on crate feature async only.
Source§

impl<T> Collection for [T]

Source§

type Idx = usize

Source§

type Output = T

Source§

type ShadowLocks = Vec<RwLock<()>>

Source§

type ShadowLocksAsync = Vec<RwLock<()>>

Available on crate feature async only.
Source§

fn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>

Source§

fn index_mut( &mut self, index: impl Borrow<Self::Idx>, ) -> Option<&mut Self::Output>

Source§

fn indices(&self) -> impl Iterator<Item = Self::Idx>

Source§

fn shadow_locks(&self) -> Self::ShadowLocks

Source§

fn shadow_locks_async(&self) -> Self::ShadowLocksAsync

Available on crate feature async only.
Source§

impl<T> Collection for VecDeque<T>

Source§

type Idx = usize

Source§

type Output = T

Source§

type ShadowLocks = VecDeque<RwLock<()>>

Source§

type ShadowLocksAsync = VecDeque<RwLock<()>>

Available on crate feature async only.
Source§

fn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>

Source§

fn index_mut( &mut self, index: impl Borrow<Self::Idx>, ) -> Option<&mut Self::Output>

Source§

fn indices(&self) -> impl Iterator<Item = Self::Idx>

Source§

fn shadow_locks(&self) -> Self::ShadowLocks

Source§

fn shadow_locks_async(&self) -> Self::ShadowLocksAsync

Available on crate feature async only.
Source§

impl<T> Collection for Vec<T>

Source§

type Idx = usize

Source§

type Output = T

Source§

type ShadowLocks = Vec<RwLock<()>>

Source§

type ShadowLocksAsync = Vec<RwLock<()>>

Available on crate feature async only.
Source§

fn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>

Source§

fn index_mut( &mut self, index: impl Borrow<Self::Idx>, ) -> Option<&mut Self::Output>

Source§

fn indices(&self) -> impl Iterator<Item = Self::Idx>

Source§

fn shadow_locks(&self) -> Self::ShadowLocks

Source§

fn shadow_locks_async(&self) -> Self::ShadowLocksAsync

Available on crate feature async only.
Source§

impl<T, const N: usize> Collection for [T; N]

Source§

type Idx = usize

Source§

type Output = T

Source§

type ShadowLocks = Vec<RwLock<()>>

Source§

type ShadowLocksAsync = Vec<RwLock<()>>

Available on crate feature async only.
Source§

fn index(&self, index: impl Borrow<Self::Idx>) -> Option<&Self::Output>

Source§

fn index_mut( &mut self, index: impl Borrow<Self::Idx>, ) -> Option<&mut Self::Output>

Source§

fn indices(&self) -> impl Iterator<Item = Self::Idx>

Source§

fn shadow_locks(&self) -> Self::ShadowLocks

Source§

fn shadow_locks_async(&self) -> Self::ShadowLocksAsync

Available on crate feature async only.

Implementors§