Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::future::Future;
- pub enum AxiomError {
- Boom,
- }
- pub type AxiomResult = Result<String, AxiomError>;
- pub type Message = String;
- pub struct Context {
- pub aid: u32,
- }
- // ---- REAL CODE
- pub trait Processor<State: Send + Sync, R: Future<Output=AxiomResult>>:
- (FnMut(&mut State, &Context, &Message) -> R) + Send + Sync
- {
- }
- impl<F, R, State> Processor<State, R> for F
- where
- State: Send + Sync + 'static,
- R: Future<Output=AxiomResult>,
- F: (FnMut(&mut State, &Context, &Message) -> R) + Send + Sync + 'static,
- {
- }
- pub struct Handler<T, R: Future<Output=AxiomResult>> {
- state: T,
- processor: dyn Processor<T, R>,
- }
- impl<T, R: Future<Output=AxiomResult>> Handler<T, R> {
- pub async fn run(&mut self, context: &Context, message: &Message) -> R {
- (self.processor)(&mut self.state, context, message)
- }
- }
- // ---- Test
- pub async fn do_it(_: &mut bool, _: &Context, _: &Message) -> AxiomResult {
- Ok("Done".to_string())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement