Update dptree

Former-commit-id: eb8b384f46
This commit is contained in:
Maybe Waffle 2022-07-18 15:56:45 +04:00
parent 123c550c6c
commit f6e7c01a45
2 changed files with 43 additions and 26 deletions

View file

@ -64,7 +64,8 @@ teloxide-macros = { version = "0.6.2", optional = true }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
dptree = "0.2.1"
#dptree = "0.2.1"
dptree = { git = "https://github.com/teloxide/dptree.git", rev = "df578e4" }
tokio = { version = "1.8", features = ["fs"] }
tokio-util = "0.6"

View file

@ -1,44 +1,27 @@
use std::collections::HashSet;
use dptree::{description::EventKind, HandlerDescription};
use dptree::{
description::{EventKind, InterestSet},
HandlerDescription,
};
use teloxide_core::types::AllowedUpdate;
/// Handler description that is used by [`Dispatcher`].
///
/// [`Dispatcher`]: crate::dispatching::Dispatcher
pub struct DpHandlerDescription {
allowed: EventKind<AllowedUpdate>,
allowed: InterestSet<Kind>,
}
impl DpHandlerDescription {
pub(crate) fn of(allowed: AllowedUpdate) -> Self {
let mut set = HashSet::with_capacity(1);
set.insert(allowed);
Self { allowed: EventKind::InterestList(set) }
set.insert(Kind(allowed));
Self { allowed: InterestSet::new_filter(set) }
}
pub(crate) fn allowed_updates(&self) -> Vec<AllowedUpdate> {
use AllowedUpdate::*;
match &self.allowed {
EventKind::InterestList(set) => set.iter().copied().collect(),
EventKind::Entry => panic!("No updates were allowed"),
EventKind::UserDefined => vec![
Message,
EditedMessage,
ChannelPost,
EditedChannelPost,
InlineQuery,
ChosenInlineResult,
CallbackQuery,
ShippingQuery,
PreCheckoutQuery,
Poll,
PollAnswer,
MyChatMember,
ChatMember,
],
}
self.allowed.observed.iter().map(|Kind(x)| x).copied().collect()
}
}
@ -59,6 +42,39 @@ impl HandlerDescription for DpHandlerDescription {
Self { allowed: self.allowed.merge_branch(&other.allowed) }
}
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
struct Kind(AllowedUpdate);
impl EventKind for Kind {
fn full_set() -> HashSet<Self> {
use AllowedUpdate::*;
[
Message,
EditedMessage,
ChannelPost,
EditedChannelPost,
InlineQuery,
ChosenInlineResult,
CallbackQuery,
ShippingQuery,
PreCheckoutQuery,
Poll,
PollAnswer,
MyChatMember,
ChatMember,
]
.into_iter()
.map(Kind)
.collect()
}
fn empty_set() -> HashSet<Self> {
HashSet::new()
}
}
#[cfg(test)]
mod tests {
use crate::{