extern crate actix;
extern crate event_web;
extern crate futures;
use actix::{Actor, Context, Handler, Message, System};
use event_web::{EditEvent, FrontendErrorKind, LookupEvent, NewEvent, SendFutResponse};
use futures::IntoFuture;
#[derive(Copy, Clone, Debug)]
struct MyHandler;
impl Actor for MyHandler {
type Context = Context<Self>;
}
impl Handler<NewEvent> for MyHandler {
type Result = SendFutResponse<NewEvent>;
fn handle(&mut self, msg: NewEvent, _: &mut Self::Context) -> Self::Result {
println!("Event: {:?}", msg.0);
SendFutResponse::new(Box::new(Ok(()).into_future()) as <NewEvent as Message>::Result)
}
}
impl Handler<EditEvent> for MyHandler {
type Result = SendFutResponse<EditEvent>;
fn handle(&mut self, msg: EditEvent, _: &mut Self::Context) -> Self::Result {
println!("Event: {:?}", msg.0);
SendFutResponse::new(Box::new(Ok(()).into_future()) as <EditEvent as Message>::Result)
}
}
impl Handler<LookupEvent> for MyHandler {
type Result = SendFutResponse<LookupEvent>;
fn handle(&mut self, _: LookupEvent, _: &mut Self::Context) -> Self::Result {
SendFutResponse::new(
Box::new(Err(FrontendErrorKind::Canceled.into()).into_future())
as <LookupEvent as Message>::Result,
)
}
}
fn main() {
let sys = System::new("womp");
event_web::start(MyHandler.start(), "0.0.0.0:8000", None);
sys.run();
}