1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#![forbid(unsafe_code)]
#![warn(missing_debug_implementations, missing_docs, rust_2018_idioms, unreachable_pub)]

//! Viz Core

use viz_utils::anyhow;

mod context;
mod extract;
mod guard;
mod handler;
mod macros;
mod middleware;
mod response;

pub mod config;
pub mod types;

#[cfg(feature = "fs")]
pub mod fs;
#[cfg(feature = "sse")]
pub mod sse;
#[cfg(feature = "ws")]
pub mod ws;

#[allow(missing_docs)]
pub mod http {
    pub use headers;
    pub use http::*;
    pub use hyper::Body;
    pub use hyper::Error;

    pub type Request<T = Body> = ::http::Request<T>;
    pub type Response<T = Body> = ::http::Response<T>;
}

/// Handle Trait
pub use handle::Handle as Middleware;

/// Error
pub use anyhow::Error;

/// Result
pub type Result<T = Response, E = anyhow::Error> = anyhow::Result<T, E>;

pub use context::Context;
pub use extract::Extract;
pub use guard::Guard;
pub use handler::{Handler, HandlerBase, HandlerCamp, HandlerSuper, HandlerWrapper};
pub use middleware::{DynMiddleware, Middlewares};
pub use response::Response;

/// Responds a custom error to response.
#[macro_export]
macro_rules! reject {
    ($err:expr) => {
        return Err(how!($err));
    };
}

/// Converts a custom error to [`Response`] and then converts to [`Error`].
#[macro_export]
macro_rules! how {
    ($err:expr) => {
        Into::<Error>::into(Into::<Response>::into($err))
    };
}

pub use anyhow::{anyhow, bail, ensure};