pub struct DialogueStorage { /* private fields */ }Expand description
Per-user or per-chat FSM state keyed by (chat_id, user_id).
Stores the current dialogue state as a type-erased value so the state machine type does not need to be known at the storage level. Per-user conversation state store for finite state machines.
State is keyed by (chat_id, user_id) pairs. Any 'static type can be
stored — no shared trait is required. Use this to track where a user is
in a multi-step conversation.
§Example
ⓘ
use rustigram_bot::state::DialogueStorage;
#[derive(Clone)]
enum State { AwaitingName, AwaitingEmail { name: String } }
let storage = DialogueStorage::new();
storage.set(chat_id, user_id, State::AwaitingName);
match storage.get::<State>(chat_id, user_id) {
Some(State::AwaitingName) => { /* ask for name */ }
Some(State::AwaitingEmail { name }) => { /* ask for email */ }
None => { /* no active dialogue */ }
}
storage.remove(chat_id, user_id); // clear when doneImplementations§
Source§impl DialogueStorage
impl DialogueStorage
Sourcepub fn set<S: Any + Send + Sync + 'static>(
&self,
chat_id: i64,
user_id: i64,
state: S,
)
pub fn set<S: Any + Send + Sync + 'static>( &self, chat_id: i64, user_id: i64, state: S, )
Sets the dialogue state for a (chat_id, user_id) pair.
Trait Implementations§
Source§impl Clone for DialogueStorage
impl Clone for DialogueStorage
Source§fn clone(&self) -> DialogueStorage
fn clone(&self) -> DialogueStorage
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for DialogueStorage
impl Default for DialogueStorage
Source§fn default() -> DialogueStorage
fn default() -> DialogueStorage
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for DialogueStorage
impl !RefUnwindSafe for DialogueStorage
impl Send for DialogueStorage
impl Sync for DialogueStorage
impl Unpin for DialogueStorage
impl UnsafeUnpin for DialogueStorage
impl !UnwindSafe for DialogueStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more