pub struct InMemStorage<D> { /* private fields */ }
Expand description

A dialogue storage based on std::collections::HashMap.

Note

All your dialogues will be lost after you restart your bot. If you need to store them somewhere on a drive, you should use e.g. super::SqliteStorage or implement your own.

Implementations§

source§

impl<S> InMemStorage<S>

source

pub fn new() -> Arc<Self>

Examples found in repository?
examples/purchase.rs (line 54)
47
48
49
50
51
52
53
54
55
56
57
58
59
async fn main() {
    pretty_env_logger::init();
    log::info!("Starting purchase bot...");

    let bot = Bot::from_env();

    Dispatcher::builder(bot, schema())
        .dependencies(dptree::deps![InMemStorage::<State>::new()])
        .enable_ctrlc_handler()
        .build()
        .dispatch()
        .await;
}
More examples
Hide additional examples
examples/dialogue.rs (line 53)
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
async fn main() {
    pretty_env_logger::init();
    log::info!("Starting dialogue bot...");

    let bot = Bot::from_env();

    Dispatcher::builder(
        bot,
        Update::filter_message()
            .enter_dialogue::<Message, InMemStorage<State>, State>()
            .branch(dptree::case![State::Start].endpoint(start))
            .branch(dptree::case![State::ReceiveFullName].endpoint(receive_full_name))
            .branch(dptree::case![State::ReceiveAge { full_name }].endpoint(receive_age))
            .branch(
                dptree::case![State::ReceiveLocation { full_name, age }].endpoint(receive_location),
            ),
    )
    .dependencies(dptree::deps![InMemStorage::<State>::new()])
    .enable_ctrlc_handler()
    .build()
    .dispatch()
    .await;
}

Trait Implementations§

source§

impl<D: Debug> Debug for InMemStorage<D>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<D> Storage<D> for InMemStorage<D>where D: Clone + Send + 'static,

§

type Error = InMemStorageError

source§

fn remove_dialogue( self: Arc<Self>, chat_id: ChatId ) -> BoxFuture<'static, Result<(), Self::Error>>where D: Send + 'static,

Removes a dialogue indexed by chat_id. Read more
source§

fn update_dialogue( self: Arc<Self>, chat_id: ChatId, dialogue: D ) -> BoxFuture<'static, Result<(), Self::Error>>where D: Send + 'static,

Updates a dialogue indexed by chat_id with dialogue.
source§

fn get_dialogue( self: Arc<Self>, chat_id: ChatId ) -> BoxFuture<'static, Result<Option<D>, Self::Error>>

Returns the dialogue indexed by chat_id.

Auto Trait Implementations§

§

impl<D> !RefUnwindSafe for InMemStorage<D>

§

impl<D> Send for InMemStorage<D>where D: Send,

§

impl<D> Sync for InMemStorage<D>where D: Send,

§

impl<D> Unpin for InMemStorage<D>where D: Unpin,

§

impl<D> UnwindSafe for InMemStorage<D>where D: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Erasable for T

§

unsafe fn unerase(this: NonNull<Erased>) -> NonNull<T>

Unerase this erased pointer. Read more
§

const ACK_1_1_0: bool = true

Available on non-enforce_1_1_0_semantics only.
Whether this implementor has acknowledged the 1.1.0 update to unerase’s documented implementation requirements. Read more
§

fn erase(this: NonNull<Self>) -> NonNull<Erased>

Turn this erasable pointer into an erased pointer. Read more
source§

impl<T> From<T> for T

const: unstable · 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 Twhere U: From<T>,

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

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

§

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