extern crate hyper; #[macro_use] extern crate serde_derive; extern crate serv; extern crate tokio; use hyper::rt::Future; #[derive(Serialize)] struct HelloResp { msg: String, } fn hello(_req: serv::Empty) -> serv::error::Result { Ok(HelloResp { msg: "hello, world".to_owned(), }) } fn main() { use serv::server::{Routes, Server}; let addr = ([127, 0, 0, 1], 3000).into(); let mut routes = Routes::new(); routes.push(hyper::Method::GET, "/", serv::sync::serv(hello)); let server = Server::new(routes); let server = hyper::server::Server::bind(&addr) .serve(move || Ok::<_, hyper::Error>(server.clone())) .map_err(|e| eprintln!("failed to serve: {:?}", e)); let mut rt = tokio::runtime::current_thread::Runtime::new().expect("failed to create runtime"); rt.block_on(server).expect("error on runtime"); }