Crate spirit_hyper[−][src]
Spirit helper for Hyper
This allows having Hyper servers auto-spawned from configuration. It is possible to put them on top of arbitrary stream-style IO objects (TcpStream, UdsStream, these wrapped in SSL...).
Examples
#![type_length_limit="8388608"] extern crate failure; extern crate hyper; extern crate serde; #[macro_use] extern crate serde_derive; extern crate spirit; extern crate spirit_hyper; use std::default::Default; use hyper::{Body, Request, Response}; use spirit::{Empty, Spirit, SpiritInner}; use spirit_hyper::HttpServer; const DEFAULT_CONFIG: &str = r#" [server] port = 1234 "#; #[derive(Default, Deserialize)] struct Config { server: HttpServer, } impl Config { fn server(&self) -> HttpServer { self.server.clone() } } fn request(_: &SpiritInner<Empty, Config>, _req: Request<Body>, _: &Empty) -> Response<Body> { Response::new(Body::from("Hello world\n")) } fn main() { Spirit::<_, Empty, _>::new(Config::default()) .config_defaults(DEFAULT_CONFIG) .config_helper(Config::server, spirit_hyper::service_fn_ok(request), "Server") .run(|spirit| { Ok(()) }); }
Further examples are in the git repository.
Known problems
- Not many helper generators are present ‒ only
service_fn_ok
for now And that one doesn't (yet) support futures. - It creates some huge types under the hood. For now, if the compiler complains about
type_length_limit
, try increasing it (maybe even multiple times). This might be overcome in the future, but for now, the main downside to it is probably compile times.
Structs
HyperServer |
A configuration fragment that can spawn Hyper server. |
Traits
ConnAction |
A trait describing the connection action. |
Functions
service_fn_ok |
A helper to create a |
Type Definitions
HttpServer |
A type alias for http (plain TCP) hyper server. |