use trait aliases
This commit is contained in:
parent
58b3153a81
commit
d78ea520ca
12
src/lib.rs
12
src/lib.rs
|
@ -1,3 +1,5 @@
|
||||||
|
#![feature(trait_alias)]
|
||||||
|
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
use crate::types::Message;
|
use crate::types::Message;
|
||||||
|
@ -10,10 +12,12 @@ use std::{
|
||||||
time::{SystemTime, UNIX_EPOCH},
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub trait Handler = Fn(Message, Rc<Malestorm>) -> Result<(), String> + 'static;
|
||||||
|
|
||||||
pub struct Malestorm<'a> {
|
pub struct Malestorm<'a> {
|
||||||
node: RefCell<Node>,
|
node: RefCell<Node>,
|
||||||
io: MalestormIo,
|
io: MalestormIo,
|
||||||
pub handlers: HashMap<&'a str, Box<dyn Fn(Message, Rc<Malestorm>) -> Result<(), String>>>,
|
pub handlers: HashMap<&'a str, Box<dyn Handler>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Node {
|
struct Node {
|
||||||
|
@ -130,11 +134,7 @@ impl<'a> Malestorm<'a> {
|
||||||
format!("{}_{}", s1, s2)
|
format!("{}_{}", s1, s2)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register(
|
pub fn register(&mut self, name: &'a str, func: impl Handler) {
|
||||||
&mut self,
|
|
||||||
name: &'a str,
|
|
||||||
func: impl Fn(Message, Rc<Malestorm>) -> Result<(), String> + 'a + 'static,
|
|
||||||
) {
|
|
||||||
self.handlers.insert(name, Box::new(func));
|
self.handlers.insert(name, Box::new(func));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user