mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-08 19:33:53 +01:00
Rename the generics
This commit is contained in:
parent
c8a1bdce25
commit
1547034741
3 changed files with 19 additions and 19 deletions
|
@ -4,8 +4,8 @@ use crate::{
|
||||||
types::{ChatKind, Update, UpdateKind},
|
types::{ChatKind, Update, UpdateKind},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Dispatcher<'a, S, H> {
|
pub struct Dispatcher<'a, Session, H> {
|
||||||
storage: Box<dyn Storage<Session = S> + 'a>,
|
storage: Box<dyn Storage<Session> + 'a>,
|
||||||
handler: H,
|
handler: H,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,10 +28,10 @@ mod macros {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, S, H> Dispatcher<'a, S, H>
|
impl<'a, Session, H> Dispatcher<'a, Session, H>
|
||||||
where
|
where
|
||||||
S: Default + 'a,
|
Session: Default + 'a,
|
||||||
H: Handler<S>,
|
H: Handler<Session>,
|
||||||
{
|
{
|
||||||
pub fn new(handler: H) -> Self {
|
pub fn new(handler: H) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -42,7 +42,7 @@ where
|
||||||
|
|
||||||
pub fn with_storage<Stg>(handler: H, storage: Stg) -> Self
|
pub fn with_storage<Stg>(handler: H, storage: Stg) -> Self
|
||||||
where
|
where
|
||||||
Stg: Storage<Session = S> + 'a,
|
Stg: Storage<Session> + 'a,
|
||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
storage: Box::new(storage),
|
storage: Box::new(storage),
|
||||||
|
|
|
@ -4,20 +4,22 @@ use super::Storage;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Default)]
|
#[derive(Clone, Debug, Eq, PartialEq, Default)]
|
||||||
pub struct InMemStorage<S> {
|
pub struct InMemStorage<Session> {
|
||||||
map: HashMap<i64, S>,
|
map: HashMap<i64, Session>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<S> Storage for InMemStorage<S> {
|
impl<Session> Storage<Session> for InMemStorage<Session> {
|
||||||
type Session = S;
|
async fn remove_session(&mut self, chat_id: i64) -> Option<Session> {
|
||||||
|
|
||||||
async fn remove_session(&mut self, chat_id: i64) -> Option<S> {
|
|
||||||
self.map.remove(&chat_id)
|
self.map.remove(&chat_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_session(&mut self, chat_id: i64, state: S) -> Option<S> {
|
async fn update_session(
|
||||||
|
&mut self,
|
||||||
|
chat_id: i64,
|
||||||
|
state: Session,
|
||||||
|
) -> Option<Session> {
|
||||||
self.map.insert(chat_id, state)
|
self.map.insert(chat_id, state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,11 @@ pub use in_mem_storage::InMemStorage;
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Storage {
|
pub trait Storage<Session> {
|
||||||
type Session;
|
async fn remove_session(&mut self, chat_id: i64) -> Option<Session>;
|
||||||
|
|
||||||
async fn remove_session(&mut self, chat_id: i64) -> Option<Self::Session>;
|
|
||||||
async fn update_session(
|
async fn update_session(
|
||||||
&mut self,
|
&mut self,
|
||||||
chat_id: i64,
|
chat_id: i64,
|
||||||
state: Self::Session,
|
state: Session,
|
||||||
) -> Option<Self::Session>;
|
) -> Option<Session>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue