pub struct Messages<S> { /* private fields */ }
Expand description
A storage of state per message. See the module’s docs to learn how to use it.
Implementations§
source§impl<S> Messages<S>
impl<S> Messages<S>
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs a new message storage with capacity for n
messages.
sourcepub fn all_messages(&self) -> impl Iterator<Item = MessageId> + '_
pub fn all_messages(&self) -> impl Iterator<Item = MessageId> + '_
Returns an iterator over the stored messages.
sourcepub fn messages_in_chat_by_id(
&self,
chat_id: Id
) -> impl Iterator<Item = Id> + '_
pub fn messages_in_chat_by_id(
&self,
chat_id: Id
) -> impl Iterator<Item = Id> + '_
Returns an iterator over stored message IDs for a chat by its ID.
sourcepub fn messages_in_chat<C>(&self, context: &C) -> impl Iterator<Item = Id> + '_where
C: Message,
pub fn messages_in_chat<C>(&self, context: &C) -> impl Iterator<Item = Id> + '_where
C: Message,
Returns an iterator over stored message IDs for a chat, which ID is inferred from the context.
sourcepub fn all_states(&self) -> impl Iterator<Item = &S>
pub fn all_states(&self) -> impl Iterator<Item = &S>
Returns an iterator over the stored states.
sourcepub fn states_in_chat_by_id(&self, chat_id: Id) -> impl Iterator<Item = &S>
pub fn states_in_chat_by_id(&self, chat_id: Id) -> impl Iterator<Item = &S>
Returns an iterator over stored states for messages in a chat by its ID.
sourcepub fn states_in_chat<C>(&self, context: &C) -> impl Iterator<Item = &S>where
C: Message,
pub fn states_in_chat<C>(&self, context: &C) -> impl Iterator<Item = &S>where
C: Message,
Returns an iterator over stored states for messages in a chat, which ID is inferred from the context.
sourcepub fn iter(&self) -> impl Iterator<Item = (MessageId, &S)>
pub fn iter(&self) -> impl Iterator<Item = (MessageId, &S)>
Returns an iterator over stored messages and their states.
sourcepub fn iter_in_chat_by_id(&self, chat_id: Id) -> impl Iterator<Item = (Id, &S)>
pub fn iter_in_chat_by_id(&self, chat_id: Id) -> impl Iterator<Item = (Id, &S)>
Returns an iterator over stored messages and their states in a chat by its ID.
sourcepub fn iter_in_chat<C>(&self, context: &C) -> impl Iterator<Item = (Id, &S)>where
C: Message,
pub fn iter_in_chat<C>(&self, context: &C) -> impl Iterator<Item = (Id, &S)>where
C: Message,
Returns an iterator over stored messages and their states in a chat, which ID is inferred from the context.
sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (MessageId, &mut S)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (MessageId, &mut S)>
Returns a mutable iterator over the stored messages and their states.
sourcepub fn iter_mut_in_chat_by_id(
&mut self,
chat_id: Id
) -> impl Iterator<Item = (Id, &mut S)>
pub fn iter_mut_in_chat_by_id(
&mut self,
chat_id: Id
) -> impl Iterator<Item = (Id, &mut S)>
Returns a mutable iterator over the stored messages and their states in a chat by its ID.
sourcepub fn iter_mut_in_chat<C>(
&mut self,
context: &C
) -> impl Iterator<Item = (Id, &mut S)>where
C: Message,
pub fn iter_mut_in_chat<C>(
&mut self,
context: &C
) -> impl Iterator<Item = (Id, &mut S)>where
C: Message,
Returns a mutable iterator over the stored messages and their states in a chat, which ID is inferred from the context.
sourcepub fn into_iter_in_chat_by_id(
self,
chat_id: Id
) -> impl Iterator<Item = (Id, S)>
pub fn into_iter_in_chat_by_id(
self,
chat_id: Id
) -> impl Iterator<Item = (Id, S)>
Returns an owning iterator over the stored messages and their states in a chat by its ID.
sourcepub fn into_iter_in_chat<C>(self, context: &C) -> impl Iterator<Item = (Id, S)>where
C: Message,
pub fn into_iter_in_chat<C>(self, context: &C) -> impl Iterator<Item = (Id, S)>where
C: Message,
Returns an owning iterator over the stored messages and their states in a chat, which ID is inferred from the context.
sourcepub fn len_in_chat_by_id(&self, chat_id: Id) -> usize
pub fn len_in_chat_by_id(&self, chat_id: Id) -> usize
Returns how many messages from a chat are stored.
sourcepub fn len_in_chat<C>(&self, context: &C) -> usizewhere
C: Message,
pub fn len_in_chat<C>(&self, context: &C) -> usizewhere
C: Message,
Returns how many messages from a chat, which ID is inferred from the context, are stored.
sourcepub fn is_empty_in_chat_by_id(&self, chat_id: Id) -> bool
pub fn is_empty_in_chat_by_id(&self, chat_id: Id) -> bool
Returns if the store does not have messages from a chat.
sourcepub fn is_empty_in_chat<C>(&self, context: &C) -> boolwhere
C: Message,
pub fn is_empty_in_chat<C>(&self, context: &C) -> boolwhere
C: Message,
Returns if the store does not have messages from a chat, inferring its ID from the context.
sourcepub fn drain(&mut self) -> impl Iterator<Item = (MessageId, S)> + '_
pub fn drain(&mut self) -> impl Iterator<Item = (MessageId, S)> + '_
Clears the storage, returning each stored item in an iterator.
sourcepub fn clear_in_chat_by_id(&mut self, chat_id: Id)
pub fn clear_in_chat_by_id(&mut self, chat_id: Id)
Deletes state for all messages from a chat.
sourcepub fn clear_in_chat<C>(&mut self, context: &C)where
C: Message,
pub fn clear_in_chat<C>(&mut self, context: &C)where
C: Message,
Deletes state for all messages from a chat, inferring its ID from the context.
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity to already stored messages.
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 message’s state, inferring its ID from the context.
sourcepub fn get_mut_by_id(&mut self, id: MessageId) -> Option<&mut S>
pub fn get_mut_by_id(&mut self, id: MessageId) -> Option<&mut S>
Gets a mutable reference to a message’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 message’s state, inferring its ID from the context.
sourcepub fn entry_by_id(&mut self, id: MessageId) -> Entry<'_, MessageId, S>
pub fn entry_by_id(&mut self, id: MessageId) -> Entry<'_, MessageId, S>
Gets an entry to a message’s state by its ID.
sourcepub fn entry<C>(&mut self, context: &C) -> Entry<'_, MessageId, S>where
C: Message,
pub fn entry<C>(&mut self, context: &C) -> Entry<'_, MessageId, S>where
C: Message,
Gets an entry to a message’s state, inferring its ID from the context.
sourcepub fn has_by_id(&self, id: MessageId) -> bool
pub fn has_by_id(&self, id: MessageId) -> bool
Checks if there’s state for a message by its ID.
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 message, inferring its ID from the context.
sourcepub fn insert_by_id(&mut self, id: MessageId, value: S) -> Option<S>
pub fn insert_by_id(&mut self, id: MessageId, value: S) -> Option<S>
Inserts state for a message 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 message, inferring its ID from the context. Returns the previous state.
sourcepub fn remove_by_id(&mut self, id: MessageId) -> Option<S>
pub fn remove_by_id(&mut self, id: MessageId) -> Option<S>
Removes and returns a message’s state by its ID.
Trait Implementations§
source§impl<'de, S> Deserialize<'de> for Messages<S>where
S: Deserialize<'de>,
impl<'de, S> Deserialize<'de> for Messages<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<(MessageId, &'a S)> for Messages<S>
impl<'a, S: Copy> Extend<(MessageId, &'a S)> for Messages<S>
source§fn extend<I: IntoIterator<Item = (MessageId, &'a S)>>(&mut self, iterator: I)
fn extend<I: IntoIterator<Item = (MessageId, &'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<(MessageId, S)> for Messages<S>
impl<S> Extend<(MessageId, S)> for Messages<S>
source§fn extend<I: IntoIterator<Item = (MessageId, S)>>(&mut self, iterator: I)
fn extend<I: IntoIterator<Item = (MessageId, 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
)