[][src]Struct tbot::state::chats::Chats

pub struct Chats<S> { /* fields omitted */ }

A storage of state per chat. See the module's docs to learn how to use it.

Implementations

impl<S> Chats<S>[src]

#[must_use]pub fn new() -> Self[src]

Constructs a new chat storage.

#[must_use]pub fn with_capacity(capacity: usize) -> Self[src]

Constructs a new chat storage with capacity for n chats.

pub fn chats(&self) -> impl Iterator<Item = Id> + '_[src]

Returns an iterator over the stored chat IDs.

pub fn states(&self) -> impl Iterator<Item = &S>[src]

Returns an iterator over the stored states.

pub fn iter(&self) -> impl Iterator<Item = (Id, &S)>[src]

Returns an iterator over the stored chat IDs and their states.

pub fn iter_mut(&mut self) -> impl Iterator<Item = (Id, &mut S)>[src]

Returns a mutable iterator over the stored chat IDs and their states.

#[must_use]pub fn len(&self) -> usize[src]

Returns how many chats are stored.

#[must_use]pub fn capacity(&self) -> usize[src]

Returns the storage's capacity.

#[must_use]pub fn is_empty(&self) -> bool[src]

Returns true if the store is empty.

#[must_use = "use `clear` if you don't need the iterator"]pub fn drain(&mut self) -> impl Iterator<Item = (Id, S)> + '_[src]

Clears the store, returning each stored item in an iterator.

pub fn clear(&mut self)[src]

Clears the store.

pub fn reserve(&mut self, additional: usize)[src]

Reserves capacity for n additional chats.

pub fn shrink_to_fit(&mut self)[src]

Shrinks the storage to already stored chats.

#[must_use]pub fn get_by_id(&self, id: Id) -> Option<&S>[src]

Gets a chat's state by its ID.

#[must_use]pub fn get<C>(&self, context: &C) -> Option<&S> where
    C: Message
[src]

Gets a chat's state, inferring its ID from the context.

#[must_use]pub fn get_mut_by_id(&mut self, id: Id) -> Option<&mut S>[src]

Gets a mutable reference to a chat's state by its ID.

#[must_use]pub fn get_mut<C>(&mut self, context: &C) -> Option<&mut S> where
    C: Message
[src]

Gets a mutable reference to a chat's state, inferring its ID from the context.

#[must_use]pub fn entry_by_id(&mut self, id: Id) -> Entry<'_, Id, S>[src]

Gets an entry for a chat's state by its ID.

#[must_use]pub fn entry<C>(&mut self, context: &C) -> Entry<'_, Id, S> where
    C: Message
[src]

Gets an entry for a chat's state, inferring its ID from the context.

#[must_use]pub fn has_by_id(&self, id: Id) -> bool[src]

Checks if there's state for a chat by its ID.

#[must_use]pub fn has<C>(&self, context: &C) -> bool where
    C: Message
[src]

Checks if there's state for a chat, inferring its ID from the context.

pub fn insert_by_id(&mut self, id: Id, value: S) -> Option<S>[src]

Inserts state for a chat by its ID. Returns the previous state.

pub fn insert<C>(&mut self, context: &C, value: S) -> Option<S> where
    C: Message
[src]

Inserts state for a chat, inferring its ID from the context. Returns the previous state.

pub fn remove_by_id(&mut self, id: Id) -> Option<S>[src]

Removes and returns a chat's state by its ID.

pub fn remove<C>(&mut self, context: &C) -> Option<S> where
    C: Message
[src]

Removes and returns a chat's state, inferring its ID from the context.

pub fn retain<P>(&mut self, predicate: P) where
    P: FnMut(Id, &mut S) -> bool
[src]

Calls the predicate for each stored entry and deletes entries for which the predicate returns false.

Trait Implementations

impl<S: Clone> Clone for Chats<S>[src]

impl<S: Debug> Debug for Chats<S>[src]

impl<S> Default for Chats<S>[src]

impl<'de, S> Deserialize<'de> for Chats<S> where
    S: Deserialize<'de>, 
[src]

impl<S: Eq> Eq for Chats<S>[src]

impl<'a, S: Copy> Extend<(Id, &'a S)> for Chats<S>[src]

impl<S> Extend<(Id, S)> for Chats<S>[src]

impl<S> FromIterator<(Id, S)> for Chats<S>[src]

impl<S> Index<Id> for Chats<S>[src]

type Output = S

The returned type after indexing.

impl<S> IntoIterator for Chats<S>[src]

type Item = (Id, S)

The type of the elements being iterated over.

type IntoIter = IntoIter<Id, S>

Which kind of iterator are we turning this into?

impl<'a, S> IntoIterator for &'a Chats<S>[src]

type Item = (Id, &'a S)

The type of the elements being iterated over.

type IntoIter = Iter<'a, S>

Which kind of iterator are we turning this into?

impl<'a, S> IntoIterator for &'a mut Chats<S>[src]

type Item = (Id, &'a mut S)

The type of the elements being iterated over.

type IntoIter = IterMut<'a, S>

Which kind of iterator are we turning this into?

impl<S: PartialEq> PartialEq<Chats<S>> for Chats<S>[src]

impl<S> Serialize for Chats<S> where
    S: Serialize
[src]

impl<S> StructuralEq for Chats<S>[src]

impl<S> StructuralPartialEq for Chats<S>[src]

Auto Trait Implementations

impl<S> RefUnwindSafe for Chats<S> where
    S: RefUnwindSafe

impl<S> Send for Chats<S> where
    S: Send

impl<S> Sync for Chats<S> where
    S: Sync

impl<S> Unpin for Chats<S> where
    S: Unpin

impl<S> UnwindSafe for Chats<S> where
    S: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> WithSubscriber for T[src]