pub struct StateManager { /* private fields */ }Expand description
Manages persistence of Telegram bot state to disk.
Implementations§
Source§impl StateManager
impl StateManager
Sourcepub fn new(path: impl Into<PathBuf>) -> Self
pub fn new(path: impl Into<PathBuf>) -> Self
Create a new StateManager that reads/writes to the given path.
Sourcepub fn load(&self) -> TelegramResult<Option<TelegramState>>
pub fn load(&self) -> TelegramResult<Option<TelegramState>>
Load state from disk. Returns None if the file doesn’t exist.
Sourcepub fn save(&self, state: &TelegramState) -> TelegramResult<()>
pub fn save(&self, state: &TelegramState) -> TelegramResult<()>
Save state to disk using atomic write (temp file + rename).
Sourcepub fn load_or_default(&self) -> TelegramResult<TelegramState>
pub fn load_or_default(&self) -> TelegramResult<TelegramState>
Load existing state or create a fresh empty state.
Sourcepub fn add_pending_question(
&self,
state: &mut TelegramState,
loop_id: &str,
message_id: i32,
) -> TelegramResult<()>
pub fn add_pending_question( &self, state: &mut TelegramState, loop_id: &str, message_id: i32, ) -> TelegramResult<()>
Add a pending question for a given loop.
Sourcepub fn remove_pending_question(
&self,
state: &mut TelegramState,
loop_id: &str,
) -> TelegramResult<()>
pub fn remove_pending_question( &self, state: &mut TelegramState, loop_id: &str, ) -> TelegramResult<()>
Remove a pending question for a given loop.
Sourcepub fn get_loop_for_reply(
&self,
state: &TelegramState,
reply_message_id: i32,
) -> Option<String>
pub fn get_loop_for_reply( &self, state: &TelegramState, reply_message_id: i32, ) -> Option<String>
Given a reply_to_message_id, find which loop it belongs to.
Auto Trait Implementations§
impl Freeze for StateManager
impl RefUnwindSafe for StateManager
impl Send for StateManager
impl Sync for StateManager
impl Unpin for StateManager
impl UnwindSafe for StateManager
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
Source§impl<T> Erasable for T
impl<T> Erasable for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more