Struct canteen::Canteen
[−]
[src]
pub struct Canteen { // some fields omitted }
The primary struct provided by the library. The aim is to have a similar interface to Flask, the Python microframework.
Methods
impl Canteen
[src]
fn new<A: ToSocketAddrs>(addr: A) -> Canteen
fn add_route(&mut self, path: &str, mlist: &[Method], handler: fn(&Request) -> Response) -> &mut Canteen
Adds a new route definition to be handled by Canteen.
Examples
fn handler(_: &Request) -> Response { utils::make_response("<b>Hello, world!</b>", "text/html", 200) } fn main() { let cnt = Canteen::new(("127.0.0.1", 8080)); cnt.add_route("/hello", &[Request::Get], handler); }
fn set_default(&mut self, handler: fn(&Request) -> Response)
Defines a default route for undefined paths.
Examples
let cnt = Canteen::new(("127.0.0.1", 8080)); cnt.set_default(canteen::utils::err_404);
fn run(&mut self)
Creates the listener and starts a Canteen server's event loop.
Examples
let cnt = Canteen::new(("127.0.0.1", 8080));
Trait Implementations
impl Handler for Canteen
[src]
type Timeout = ()
type Message = u32
fn ready(&mut self, evl: &mut EventLoop<Canteen>, token: Token, events: EventSet)
Invoked when the socket represented by token
is ready to be operated on. events
indicates the specific operations that are ready to be performed. Read more
fn notify(&mut self, event_loop: &mut EventLoop<Self>, msg: Self::Message)
Invoked when a message has been received via the event loop's channel.
fn timeout(&mut self, event_loop: &mut EventLoop<Self>, timeout: Self::Timeout)
Invoked when a timeout has completed.
fn interrupted(&mut self, event_loop: &mut EventLoop<Self>)
Invoked when EventLoop
has been interrupted by a signal interrupt.
fn tick(&mut self, event_loop: &mut EventLoop<Self>)
Invoked at the end of an event loop tick.