Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate hyper;
- use std::io::Write;
- use std::sync::Mutex;
- use hyper::*;
- type Route = (method::Method, String, Box<Fn(server::Request, server::Response)>);
- struct MyServer {
- routes: Vec<Route>
- }
- struct MyHandler {
- routes: Mutex<Vec<Route>>
- }
- impl server::Handler for MyHandler {
- fn handle(&self, req: server::Request, mut res: server::Response) {
- // This is not important
- }
- }
- impl MyServer {
- pub fn new() -> MyServer {
- MyServer {
- routes: Vec::new(),
- }
- }
- fn route<T: 'static + Fn(server::Request, server::Response)>(&mut self, verb: method::Method, uri: &str, handler: T) {
- self.routes.push( ( verb, uri.to_string(),Box::new(handler)) )
- }
- pub fn serve(&mut self) {
- server::Server::http("127.0.0.1:8080").unwrap()
- .handle( MyHandler {routes: Mutex::new(self.routes) } ).unwrap();
- }
- }
- fn main() {
- let mut c = MyServer::new().serve();
- }
- error: the trait bound `for<'r, 'r, 'r> std::ops::Fn(hyper::server::Request<'r, 'r>, hyper::server::Response<'r>) + 'static: std::marker::Send` is not satisfied [--explain E0277]
- --> src/main.rs:17:6
- |>
- 17 |> impl server::Handler for MyHandler {
- |> ^^^^^^^^^^^^^^^
- note: `for<'r, 'r, 'r> std::ops::Fn(hyper::server::Request<'r, 'r>, hyper::server::Response<'r>) + 'static` cannot be sent between threads safely
- note: required because it appears within the type `Box<for<'r, 'r, 'r> std::ops::Fn(hyper::server::Request<'r, 'r>, hyper::server::Response<'r>) + 'static>`
- note: required because it appears within the type `(hyper::method::Method, std::string::String, Box<for<'r, 'r, 'r> std::ops::Fn(hyper::server::Request<'r, 'r>, hyper::server::Response<'r>) + 'static>)`
- note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<(hyper::method::Method, std::string::String, Box<for<'r, 'r, 'r> std::ops::Fn(hyper::server::Request<'r, 'r>, hyper::server::Response<'r>) + 'static>)>`
- note: required because it appears within the type `alloc::raw_vec::RawVec<(hyper::method::Method, std::string::String, Box<for<'r, 'r, 'r> std::ops::Fn(hyper::server::Request<'r, 'r>, hyper::server::Response<'r>) + 'static>)>`
- note: required because it appears within the type `std::vec::Vec<(hyper::method::Method, std::string::String, Box<for<'r, 'r, 'r> std::ops::Fn(hyper::server::Request<'r, 'r>, hyper::server::Response<'r>) + 'static>)>`
- note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Mutex<std::vec::Vec<(hyper::method::Method, std::string::String, Box<for<'r, 'r, 'r> std::ops::Fn(hyper::server::Request<'r, 'r>, hyper::server::Response<'r>) + 'static>)>>`
- note: required because it appears within the type `MyHandler`
- note: required by `hyper::server::Handler`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement