[][src]Struct sincere::app::App

pub struct App { /* fields omitted */ }

App container.

use sincere::App;

fn main() {
    let mut app = App::new();

    app.get("/", |context| {
        context.response.from_text("Hello world!").unwrap();
    });

    app.run("0.0.0.0:10001", 4).unwrap();
}

Methods

impl App[src]

pub fn new() -> App[src]

Create an app container.

Examples

use sincere::App;

let app = App::new();

pub fn add<H>(&mut self, method: Method, pattern: &str, handle: H) -> &mut Route where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add route handle to app.

Examples

use sincere::App;
use sincere::http::Method;

let mut app = App::new();

app.add(Method::GET, "/", |context| {
    context.response.from_text("Get method!").unwrap();
});

pub fn get<H>(&mut self, pattern: &str, handle: H) -> &mut Route where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add route handle to app with GET method.

Examples

use sincere::App;
use sincere::http::Method;

let mut app = App::new();

app.get("/", |context| {
   context.response.from_text("Get method!").unwrap();
});

pub fn put<H>(&mut self, pattern: &str, handle: H) -> &mut Route where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add route handle to app with PUT method.

Examples

use sincere::App;
use sincere::http::Method;

let mut app = App::new();

app.put("/", |context| {
   context.response.from_text("Put method!").unwrap();
});

pub fn post<H>(&mut self, pattern: &str, handle: H) -> &mut Route where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add route handle to app with POST method.

Examples

use sincere::App;
use sincere::http::Method;

let mut app = App::new();

app.post("/", |context| {
   context.response.from_text("Post method!").unwrap();
});

pub fn head<H>(&mut self, pattern: &str, handle: H) -> &mut Route where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add route handle to app with HEAD method.

Examples

use sincere::App;
use sincere::http::Method;

let mut app = App::new();

app.head("/", |context| {
   // no body?
   // context.response.from_text("Head method!").unwrap();
});

pub fn patch<H>(&mut self, pattern: &str, handle: H) -> &mut Route where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add route handle to app with PATCH method.

Examples

use sincere::App;
use sincere::http::Method;

let mut app = App::new();

app.patch("/", |context| {
   context.response.from_text("Patch method!").unwrap();
});

pub fn trace<H>(&mut self, pattern: &str, handle: H) -> &mut Route where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add route handle to app with TRACE method.

Examples

use sincere::App;
use sincere::http::Method;

let mut app = App::new();

app.trace("/", |context| {
   context.response.from_text("Trace method!").unwrap();
});

pub fn delete<H>(&mut self, pattern: &str, handle: H) -> &mut Route where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add route handle to app with DELETE method.

Examples

use sincere::App;
use sincere::http::Method;

let mut app = App::new();

app.delete("/", |context| {
   context.response.from_text("Delete method!").unwrap();
});

pub fn options<H>(&mut self, pattern: &str, handle: H) -> &mut Route where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add route handle to app with OPTIONS method.

Examples

use sincere::App;
use sincere::http::Method;

let mut app = App::new();

app.options("/", |context| {
   context.response.from_text("Options method!").unwrap();
});

pub fn connect<H>(&mut self, pattern: &str, handle: H) -> &mut Route where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add route handle to app with CONNECT method.

Examples

use sincere::App;
use sincere::http::Method;

let mut app = App::new();

app.connect("/", |context| {
   context.response.from_text("Connect method!").unwrap();
});

pub fn mount<F>(&mut self, prefix: &str, func: F) -> &mut App where
    F: Fn(&mut Group), 
[src]

Mount router group to app.

Examples

use sincere::App;

let mut app = App::new();

app.mount("/app", |group| {

    group.get("/", |context| {
        context.response.from_text("Get method!").unwrap();
    });

    group.post("/", |context| {
        context.response.from_text("Post method!").unwrap();
    });

});

pub fn mount_group(&mut self, group: Group) -> &mut App[src]

Mount router group to app.

Examples

use sincere::App;
use sincere::app::Group;

let mut group = Group::new("/app");

group.get("/", |context| {
    context.response.from_text("Get method!").unwrap();
});

group.post("/", |context| {
    context.response.from_text("Post method!").unwrap();
});

let mut app = App::new();

app.mount_group(group);

pub fn begin<H>(&mut self, handle: H) -> &mut Self where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add begin handle to app.

Examples

use sincere::App;

let mut app = App::new();

app.begin(|context| {
    context.response.from_text("begin!").unwrap();
});

pub fn before<H>(&mut self, handle: H) -> &mut Self where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add before handle to app.

Examples

use sincere::App;

let mut app = App::new();

app.before(|context| {
    context.response.from_text("before!").unwrap();
});

pub fn after<H>(&mut self, handle: H) -> &mut Self where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add after handle to app.

Examples

use sincere::App;

let mut app = App::new();

app.after(|context| {
    context.response.from_text("after!").unwrap();
});

pub fn finish<H>(&mut self, handle: H) -> &mut Self where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add finish handle to app.

Examples

use sincere::App;

let mut app = App::new();

app.finish(|context| {
    context.response.from_text("finish!").unwrap();
});

pub fn middleware<F>(&mut self, func: F) -> &mut App where
    F: Fn(&mut App), 
[src]

Use middleware

Example

use sincere::App;

let mut app = App::new();

app.middleware(|app| {
     
    app.begin(|context| {
        context.response.from_text("Hello world!").unwrap();
    });

    app.finish(|context| {
        context.response.from_text("Hello world!").unwrap();
    });

});

pub fn not_found<H>(&mut self, handle: H) where
    H: Fn(&mut Context) + Send + Sync + 'static, 
[src]

Add not-found handle to app.

Examples

use sincere::App;

let mut app = App::new();

app.not_found(|context| {
    context.response.status_code(404).from_text("Not Found!").unwrap();
});

pub fn run(&self, addr: &str, thread_size: usize) -> Result<()>[src]

Run app.

use sincere::App;

fn main() {
    let mut app = App::new();

    app.get("/", |context| {
        context.response.from_text("Hello world!").unwrap();
    });

    app.run("0.0.0.0:10001", 4).unwrap();
}

Trait Implementations

impl Default for App[src]

Auto Trait Implementations

impl Unpin for App

impl Sync for App

impl Send for App

impl !RefUnwindSafe for App

impl !UnwindSafe for App

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> Erased for T