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
#![forbid(unsafe_code)]
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]

//! Viz Core

use viz_utils::anyhow;

pub use anyhow::Error;

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

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

pub mod config;
pub mod types;

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

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

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

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

/// 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 crate::anyhow::{anyhow, bail, ensure};