use std::borrow::Cow;
use context::Context;
use response::Response;
use std::sync::Arc;
pub trait Handler: Send + Sync + 'static {
fn handle_request(&self, context: Context, response: Response);
fn description(&self) -> Option<Cow<'static, str>> {
None
}
}
impl<F: Fn(Context, Response) + Send + Sync + 'static> Handler for F {
fn handle_request(&self, context: Context, response: Response) {
self(context, response);
}
}
impl<T: Handler> Handler for Arc<T> {
fn handle_request(&self, context: Context, response: Response) {
(**self).handle_request(context, response);
}
}
impl Handler for Box<Handler> {
fn handle_request(&self, context: Context, response: Response) {
(**self).handle_request(context, response);
}
}