pub struct Chats<S> { /* private fields */ }
Expand description
A storage of state per chat. See the module’s docs to learn how to use it.
Implementations§
source§impl<S> Chats<S>
impl<S> Chats<S>
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs a new chat storage with capacity for n
chats.
sourcepub fn chats(&self) -> impl Iterator<Item = Id> + '_
pub fn chats(&self) -> impl Iterator<Item = Id> + '_
Returns an iterator over the stored chat IDs.
sourcepub fn iter(&self) -> impl Iterator<Item = (Id, &S)>
pub fn iter(&self) -> impl Iterator<Item = (Id, &S)>
Returns an iterator over the stored chat IDs and their states.
sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (Id, &mut S)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (Id, &mut S)>
Returns a mutable iterator over the stored chat IDs and their states.
sourcepub fn drain(&mut self) -> impl Iterator<Item = (Id, S)> + '_
pub fn drain(&mut self) -> impl Iterator<Item = (Id, S)> + '_
Clears the store, returning each stored item in an iterator.
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the storage to already stored chats.
sourcepub fn get<C>(&self, context: &C) -> Option<&S>where
C: Message,
pub fn get<C>(&self, context: &C) -> Option<&S>where
C: Message,
Gets a chat’s state, inferring its ID from the context.
sourcepub fn get_mut_by_id(&mut self, id: Id) -> Option<&mut S>
pub fn get_mut_by_id(&mut self, id: Id) -> Option<&mut S>
Gets a mutable reference to a chat’s state by its ID.
sourcepub fn get_mut<C>(&mut self, context: &C) -> Option<&mut S>where
C: Message,
pub fn get_mut<C>(&mut self, context: &C) -> Option<&mut S>where
C: Message,
Gets a mutable reference to a chat’s state, inferring its ID from the context.
sourcepub fn entry_by_id(&mut self, id: Id) -> Entry<'_, Id, S>
pub fn entry_by_id(&mut self, id: Id) -> Entry<'_, Id, S>
Gets an entry for a chat’s state by its ID.
sourcepub fn entry<C>(&mut self, context: &C) -> Entry<'_, Id, S>where
C: Message,
pub fn entry<C>(&mut self, context: &C) -> Entry<'_, Id, S>where
C: Message,
Gets an entry for a chat’s state, inferring its ID from the context.
sourcepub fn has<C>(&self, context: &C) -> boolwhere
C: Message,
pub fn has<C>(&self, context: &C) -> boolwhere
C: Message,
Checks if there’s state for a chat, inferring its ID from the context.
sourcepub fn insert_by_id(&mut self, id: Id, value: S) -> Option<S>
pub fn insert_by_id(&mut self, id: Id, value: S) -> Option<S>
Inserts state for a chat by its ID. Returns the previous state.
sourcepub fn insert<C>(&mut self, context: &C, value: S) -> Option<S>where
C: Message,
pub fn insert<C>(&mut self, context: &C, value: S) -> Option<S>where
C: Message,
Inserts state for a chat, inferring its ID from the context. Returns the previous state.
sourcepub fn remove_by_id(&mut self, id: Id) -> Option<S>
pub fn remove_by_id(&mut self, id: Id) -> Option<S>
Removes and returns a chat’s state by its ID.
Trait Implementations§
source§impl<'de, S> Deserialize<'de> for Chats<S>where
S: Deserialize<'de>,
impl<'de, S> Deserialize<'de> for Chats<S>where
S: Deserialize<'de>,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<'a, S: Copy> Extend<(Id, &'a S)> for Chats<S>
impl<'a, S: Copy> Extend<(Id, &'a S)> for Chats<S>
source§fn extend<I: IntoIterator<Item = (Id, &'a S)>>(&mut self, iterator: I)
fn extend<I: IntoIterator<Item = (Id, &'a S)>>(&mut self, iterator: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<S> Extend<(Id, S)> for Chats<S>
impl<S> Extend<(Id, S)> for Chats<S>
source§fn extend<I: IntoIterator<Item = (Id, S)>>(&mut self, iterator: I)
fn extend<I: IntoIterator<Item = (Id, S)>>(&mut self, iterator: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)