Struct telers::fsm::context::Context

source ·
pub struct Context<S> { /* private fields */ }
Expand description

Context is used to manage state and data of the user in specified storage

Implementations§

source§

impl<S> Context<S>

source

pub fn new(storage: S, key: StorageKey) -> Self

source§

impl<S> Context<S>
where S: Storage,

source

pub async fn set_state<State>(&self, state: State) -> Result<(), S::Error>
where State: Into<Cow<'static, str>> + Send,

Set current state

§Arguments
  • state - State
§Errors

If storage error occurs, when set state

source

pub async fn set_previous_state(&self) -> Result<(), S::Error>

Set previous state as current state

§Errors

If storage error occurs, when set previous state

§Notes

States stack is used to store states history, when user set new state, then current state will be push to the states stack, so you can use this method to back to the previous state

source

pub async fn get_state(&self) -> Result<Option<Box<str>>, S::Error>

Get current state

§Errors

If storage error occurs, when get state

§Returns

State, if state is no exists, then None will be return

source

pub async fn get_states(&self) -> Result<Box<[Box<str>]>, S::Error>

Get states stack

§Errors

If storage error occurs, when get states stack

§Notes

States stack is used to store states history, when user set new state, then current state will be push to the states stack, so you can use this method to get states history or back to the previous state

§Returns

States, if states is no exists, then empty slice will be return

source

pub async fn remove_states(&self) -> Result<(), S::Error>

Remove states stack

§Errors

If storage error occurs, when remove states stack

§Notes

States stack is used to store states history, when user set new state, then current state will be push to the states stack, so you can use this method to clear states history

source

pub async fn set_data<Key, Data>( &self, data: HashMap<Key, Data>, ) -> Result<(), S::Error>
where Data: Serialize + Send, Key: Serialize + Into<Cow<'static, str>> + Send,

Set current data

§Arguments
  • data - Data, if empty, then data will be clear
§Errors

If storage error occurs, when set data

source

pub async fn set_value<Key, Value>( &self, value_key: Key, value: Value, ) -> Result<(), S::Error>
where Value: Serialize + Send, Key: Serialize + Into<Cow<'static, str>> + Send,

Set value to the data for value key

§Arguments
  • value_key - Specified value key to set value to data
  • value - Value for value key
§Errors

If storage error occurs, when set value to data

source

pub async fn get_data<Data>(&self) -> Result<HashMap<Box<str>, Data>, S::Error>
where Data: DeserializeOwned,

Get current data

§Errors

If storage error occurs, when get data

§Returns

Data, if data is no exists, then empty HashMap will be return

source

pub async fn get_value<Key, Value>( &self, value_key: Key, ) -> Result<Option<Value>, S::Error>
where Value: DeserializeOwned, Key: Into<Cow<'static, str>> + Send,

Get value from data for value key

§Arguments
  • value_key - Specified value key to get value from data
§Errors

If storage error occurs, when get value from data

§Returns

Value, if value is no exists, then None will be return

source

pub async fn remove_data(&self) -> Result<(), S::Error>

Remove current data

§Errors

If storage error occurs, when remove data

source

pub async fn finish(&self) -> Result<(), S::Error>

Finish current context by remove state and data. This method is just shortcut for Context::remove_states and Context::remove_data methods

§Errors

If storage error occurs, when remove state or data

Trait Implementations§

source§

impl<S> Clone for Context<S>
where S: Clone,

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<S, __C> FromEventAndContext<__C> for Context<S>
where Context<S>: Clone + 'static,

§

type Error = Error

source§

fn extract( bot: Arc<Bot<__C>>, update: Arc<Update>, context: Arc<Context>, ) -> Result<Self, Self::Error>

Extracts data from Update, Context and Bot to handler argument Read more

Auto Trait Implementations§

§

impl<S> Freeze for Context<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Context<S>
where S: RefUnwindSafe,

§

impl<S> Send for Context<S>
where S: Send,

§

impl<S> Sync for Context<S>
where S: Sync,

§

impl<S> Unpin for Context<S>
where S: Unpin,

§

impl<S> UnwindSafe for Context<S>
where S: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T