Struct canteen::Canteen
[−]
[src]
pub struct Canteen { /* 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
Creates a new Canteen instance.
Examples
use canteen::Canteen; let cnt = Canteen::new(("127.0.0.1", 8081));
fn add_route(
&mut self,
path: &str,
mlist: &[Method],
handler: fn(_: &Request) -> Response
) -> &mut Canteen
&mut self,
path: &str,
mlist: &[Method],
handler: fn(_: &Request) -> Response
) -> &mut Canteen
Adds a new route definition to be handled by Canteen.
Examples
use canteen::{Canteen, Request, Response, Method}; use canteen::utils; fn handler(_: &Request) -> Response { utils::make_response("<b>Hello, world!</b>", "text/html", 200) } fn main() { let mut cnt = Canteen::new(("127.0.0.1", 8082)); cnt.add_route("/hello", &[Method::Get], handler); }
fn set_default(&mut self, handler: fn(_: &Request) -> Response)
Defines a default route for undefined paths.
Examples
use canteen::Canteen; use canteen::utils; let mut cnt = Canteen::new(("127.0.0.1", 8083)); cnt.set_default(utils::err_404);
fn run(&mut self)
Creates the listener and starts a Canteen server's event loop.
Examples
use canteen::Canteen; let cnt = Canteen::new(("127.0.0.1", 8084)); /* cnt.run(); */
Trait Implementations
impl Handler for Canteen
[src]
type Timeout = ()
type Message = (Token, Vec<u8>)
fn ready(
&mut self,
evl: &mut EventLoop<Canteen>,
token: Token,
events: EventSet
)
&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, evl: &mut EventLoop<Canteen>, msg: (Token, Vec<u8>))
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.