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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! Tsukuyomi is a next generation Web framework for Rust.

#![doc(html_root_url = "https://docs.rs/tsukuyomi/0.2.1/tsukuyomi")]
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![deny(unreachable_pub)]
#![deny(unused_extern_crates)]
#![deny(bare_trait_objects)]
#![cfg_attr(feature = "codegen", feature(use_extern_macros))]
#![cfg_attr(feature = "extern-prelude", feature(extern_prelude))]
#![cfg_attr(feature = "nightly", feature(macro_vis_matcher))]

extern crate bytes;
extern crate cookie;
#[macro_use]
extern crate failure;
#[macro_use]
extern crate futures;
extern crate http;
extern crate hyper;
extern crate indexmap;
#[macro_use]
extern crate log;
extern crate mime;
extern crate serde;
#[macro_use]
extern crate serde_json;
extern crate tokio;
extern crate tokio_tcp;
extern crate tokio_threadpool;
#[cfg(unix)]
extern crate tokio_uds;
#[cfg(test)]
#[macro_use]
extern crate matches;

#[cfg(feature = "tls")]
extern crate rustls;
#[cfg(feature = "tls")]
extern crate tokio_rustls;

#[cfg(feature = "codegen")]
extern crate tsukuyomi_codegen;

#[cfg(feature = "websocket")]
extern crate base64;
#[cfg(feature = "websocket")]
extern crate sha1;
#[cfg(feature = "websocket")]
extern crate tokio_codec;
#[cfg(feature = "websocket")]
extern crate websocket_codec;

pub mod app;
pub mod error;
pub mod handler;
pub mod input;
pub mod json;
pub mod local;
pub mod modifier;
pub mod output;
pub mod server;

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

#[doc(inline)]
pub use app::App;

#[doc(inline)]
pub use error::{Error, Result};

#[doc(inline)]
pub use handler::Handler;

#[doc(inline)]
pub use input::Input;

#[doc(inline)]
pub use modifier::Modifier;

#[doc(inline)]
pub use output::{AsyncResponder, Output, Responder};

#[cfg(feature = "codegen")]
pub use tsukuyomi_codegen::{async_handler, handler};

/// A type alias of `Result<T, E>` which will be returned from `run`.
///
/// This typed is intended to be used as the return type of `main()`.
pub type AppResult<T> = ::std::result::Result<T, ::failure::Error>;

/// Starts an HTTP server with a constructed `App` and the default server configuration.
pub fn run(app: App) -> AppResult<()> {
    let server = ::server::Server::builder().finish(app)?;
    server.serve();
    Ok(())
}