mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +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},
|
||||
};
|
||||
|
||||
pub struct Dispatcher<'a, S, H> {
|
||||
storage: Box<dyn Storage<Session = S> + 'a>,
|
||||
pub struct Dispatcher<'a, Session, H> {
|
||||
storage: Box<dyn Storage<Session> + 'a>,
|
||||
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
|
||||
S: Default + 'a,
|
||||
H: Handler<S>,
|
||||
Session: Default + 'a,
|
||||
H: Handler<Session>,
|
||||
{
|
||||
pub fn new(handler: H) -> Self {
|
||||
Self {
|
||||
|
@ -42,7 +42,7 @@ where
|
|||
|
||||
pub fn with_storage<Stg>(handler: H, storage: Stg) -> Self
|
||||
where
|
||||
Stg: Storage<Session = S> + 'a,
|
||||
Stg: Storage<Session> + 'a,
|
||||
{
|
||||
Self {
|
||||
storage: Box::new(storage),
|
||||
|
|
|
@ -4,20 +4,22 @@ use super::Storage;
|
|||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Default)]
|
||||
pub struct InMemStorage<S> {
|
||||
map: HashMap<i64, S>,
|
||||
pub struct InMemStorage<Session> {
|
||||
map: HashMap<i64, Session>,
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
#[async_trait]
|
||||
impl<S> Storage for InMemStorage<S> {
|
||||
type Session = S;
|
||||
|
||||
async fn remove_session(&mut self, chat_id: i64) -> Option<S> {
|
||||
impl<Session> Storage<Session> for InMemStorage<Session> {
|
||||
async fn remove_session(&mut self, chat_id: i64) -> Option<Session> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,11 @@ pub use in_mem_storage::InMemStorage;
|
|||
|
||||
#[async_trait(?Send)]
|
||||
#[async_trait]
|
||||
pub trait Storage {
|
||||
type Session;
|
||||
|
||||
async fn remove_session(&mut self, chat_id: i64) -> Option<Self::Session>;
|
||||
pub trait Storage<Session> {
|
||||
async fn remove_session(&mut self, chat_id: i64) -> Option<Session>;
|
||||
async fn update_session(
|
||||
&mut self,
|
||||
chat_id: i64,
|
||||
state: Self::Session,
|
||||
) -> Option<Self::Session>;
|
||||
state: Session,
|
||||
) -> Option<Session>;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue