use std; use std::rc::Rc; use std::marker::PhantomData; use actix::Actor; use bytes::Bytes; use futures::unsync::mpsc::Receiver; use task::Task; use context::HttpContext; use resource::HttpResponse; use httpmessage::{HttpRequest, HttpMessage}; pub type Payload = Receiver; #[derive(Debug)] pub enum PayloadItem { Eof, Chunk(Bytes) } impl PayloadItem { pub fn is_eof(&self) -> bool { match *self { PayloadItem::Eof => true, _ => false, } } pub fn is_chunk(&self) -> bool { !self.is_eof() } } #[derive(Debug)] #[cfg_attr(feature="cargo-clippy", allow(large_enum_variant))] pub enum Frame { Message(HttpMessage), Payload(Option), } pub trait RouteHandler: 'static { fn handle(&self, req: HttpRequest, payload: Option, state: Rc) -> Task; } pub trait Route: Actor> { type State; fn request(req: HttpRequest, payload: Option, ctx: &mut HttpContext) -> HttpResponse; fn factory() -> RouteFactory { RouteFactory(PhantomData) } } pub struct RouteFactory, S>(PhantomData); impl RouteHandler for RouteFactory where A: Route, S: 'static { fn handle(&self, req: HttpRequest, payload: Option, state: Rc) -> Task { let mut ctx = HttpContext::new(unsafe{std::mem::uninitialized()}, state); A::request(req, payload, &mut ctx).into(ctx) } }