Rename the generics

This commit is contained in:
Temirkhan Myrzamadi 2020-01-08 16:51:10 +06:00
parent c8a1bdce25
commit 1547034741
3 changed files with 19 additions and 19 deletions

View file

@ -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),

View file

@ -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)
}
}

View file

@ -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>;
}