Skip to main content

Result

Type Alias Result 

Source
pub type Result<T = (), E = Error> = Result<T, E>;
Expand description

The handler result.

use web_net::{App, Context, Error, Guest, Result, get};

fn show(cx: &mut Context<'_, Guest>) -> Result {
    let id: u32 = cx.param_as("id")?;
    if id == 0 {
        return Err(Error::not_found("post.none"));
    }
    cx.text(200, "a post")
}

let app = App::builder().route(get("/posts/:id", show)).build()?;
let r = serve_net::testing::respond(&app, b"GET /posts/0 HTTP/1.1\r\nHost: localhost\r\n\r\n");
assert_eq!(r.status, 404);

Aliased Type§

pub enum Result<T = (), E = Error> {
    Ok(T),
    Err(E),
}

Variants§

§1.0.0

Ok(T)

Contains the success value

§1.0.0

Err(E)

Contains the error value