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]
impl Canteen
pub fn new() -> Canteen
[src]
pub fn new() -> Canteen
pub fn bind<A: ToSocketAddrs>(&mut self, addr: A)
[src]
pub fn bind<A: ToSocketAddrs>(&mut self, addr: A)
Bind to an address on which to listen for connections
Examples
ⓘThis example is not tested
use canteen::Canteen; let mut cnt = Canteen::new(); cnt.bind(("127.0.0.1", 8080));
pub fn add_route(
&mut self,
path: &str,
mlist: &[Method],
handler: fn(_: &Request) -> Response
) -> &mut Canteen
[src]
pub 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
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(); cnt.add_route("/hello", &[Method::Get], handler); }
pub fn set_default(&mut self, handler: fn(_: &Request) -> Response)
[src]
pub 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(); cnt.set_default(utils::err_404);
pub fn run(&mut self)
[src]
pub fn run(&mut self)
Creates the listener and starts a Canteen server's event loop.
Examples
use canteen::Canteen; let mut cnt = Canteen::new(); cnt.run();
Trait Implementations
impl Handler for Canteen
[src]
impl Handler for Canteen
type Timeout = ()
type Message = (Token, Vec<u8>)
fn ready(
&mut self,
evl: &mut EventLoop<Canteen>,
token: Token,
events: EventSet
)
[src]
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, evl: &mut EventLoop<Canteen>, msg: (Token, Vec<u8>))
[src]
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)
[src]
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>)
[src]
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>)
[src]
fn tick(&mut self, event_loop: &mut EventLoop<Self>)
Invoked at the end of an event loop tick.