1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
use error::ErrCode; use core::{IoContext, ThreadIoContext, Upcast, FnOp}; pub trait Sender<R, E, G: WrappedHandler<R, E>> : FnOp + Upcast<FnOp + Send> { fn send(self: Box<Self>, &IoContext, Result<R, E>); fn as_self(&self) -> &G; fn as_mut_self(&mut self) -> &mut G; } impl<R, E, G> Into<Box<FnOp + Send>> for Box<Sender<R, E, G> + Send> { fn into(self) -> Box<FnOp + Send> { self.upcast() } } pub type Operation<R, E, G> = Box<Sender<R, E, G> + Send>; pub trait Receiver<R> { fn recv(self, &IoContext) -> R; } pub struct NullReceiver; impl Receiver<()> for NullReceiver { fn recv(self, _: &IoContext) { } } pub trait WrappedHandler<R, E> { fn perform(&mut self, &IoContext, &mut ThreadIoContext, ErrCode, Operation<R, E, Self>); } pub trait Handler<R, E> : Sized { type Output; fn result(self, &IoContext, Result<R, E>) -> Self::Output; #[doc(hidden)] type Receiver : Receiver<Self::Output>; #[doc(hidden)] fn channel<G>(self, G) -> (Operation<R, E, G>, Self::Receiver) where G: WrappedHandler<R, E> + Send + 'static; } mod wrap; pub use self::wrap::{wrap}; mod strand; pub use self::strand::{Strand, StrandImmutable}; #[cfg(feature = "context")] mod coroutine; #[cfg(feature = "context")] pub use self::coroutine::{Coroutine};