A Cargo feature `runtime` is added, which is enabled by default, that includes the following: - The `client::HttpConnector`, which uses `tokio::net::TcpStream`. - The `server::AddrStream`, which uses `tokio::net::TcpListener`. - The `hyper::rt` module, which includes useful utilities to work with the runtime without needing to import `futures` or `tokio` explicity. Disabling the feature removes many of these niceties, but allows people to use hyper in environments that have an alternative runtime, without needing to download an unused one.
35 lines
932 B
Rust
35 lines
932 B
Rust
#![deny(warnings)]
|
|
extern crate hyper;
|
|
extern crate pretty_env_logger;
|
|
|
|
use hyper::{Body, Response, Server};
|
|
use hyper::service::service_fn_ok;
|
|
use hyper::rt::{self, Future};
|
|
|
|
static PHRASE: &'static [u8] = b"Hello World!";
|
|
|
|
fn main() {
|
|
pretty_env_logger::init();
|
|
|
|
let addr = ([127, 0, 0, 1], 3000).into();
|
|
|
|
// new_service is run for each connection, creating a 'service'
|
|
// to handle requests for that specific connection.
|
|
let new_service = || {
|
|
// This is the `Service` that will handle the connection.
|
|
// `service_fn_ok` is a helper to convert a function that
|
|
// returns a Response into a `Service`.
|
|
service_fn_ok(|_| {
|
|
Response::new(Body::from(PHRASE))
|
|
})
|
|
};
|
|
|
|
let server = Server::bind(&addr)
|
|
.serve(new_service)
|
|
.map_err(|e| eprintln!("server error: {}", e));
|
|
|
|
println!("Listening on http://{}", addr);
|
|
|
|
rt::run(server);
|
|
}
|