Struct seamless::api::RouteBuilder[][src]

pub struct RouteBuilder<'a> { /* fields omitted */ }

Add a new API route by providing a description (optional but encouraged) and then a handler function.

Examples

// This route expects a JSON formatted string to be provided, and echoes it straight back.
api.add("some/route/name")
   .description("This route takes some Foo's in and returns some Bar's")
   .handler(|body: Json<String>| async move { Ok::<_,std::convert::Infallible>(body.json) });

// This route delegates to an async fn to sum some values, so we can infer more types in the handler.
api.add("another.route")
   .description("This route takes an array of values and sums them")
   .handler(|body: Json<_>| sum(body.json));

async fn sum(ns: Vec<u64>) -> Result<u64, Infallible> {
    Ok(ns.into_iter().sum())
}

Implementations

impl<'a> RouteBuilder<'a>[src]

pub fn description<S: Into<String>>(self, desc: S) -> Self[src]

Add a description to the API route.

pub fn handler<A, HandlerFn: IntoHandler<ApiError, A>>(self, handler: HandlerFn)[src]

Add a handler to the API route. Until this has been added, the route doesn't "exist".

Auto Trait Implementations

impl<'a> !RefUnwindSafe for RouteBuilder<'a>[src]

impl<'a> Send for RouteBuilder<'a>[src]

impl<'a> Sync for RouteBuilder<'a>[src]

impl<'a> Unpin for RouteBuilder<'a>[src]

impl<'a> !UnwindSafe for RouteBuilder<'a>[src]

Blanket Implementations

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

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

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

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.