Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. extern crate hyper;
  2. use std::io::Write;
  3. use std::sync::Mutex;
  4.  
  5. use hyper::*;
  6.  
  7. type Route = (method::Method, String, Box<Fn(server::Request, server::Response)>);
  8.  
  9. struct MyServer {
  10. routes: Vec<Route>
  11. }
  12.  
  13. struct MyHandler {
  14. routes: Mutex<Vec<Route>>
  15. }
  16.  
  17. impl server::Handler for MyHandler {
  18. fn handle(&self, req: server::Request, mut res: server::Response) {
  19. // This is not important
  20. }
  21. }
  22.  
  23.  
  24. impl MyServer {
  25.  
  26. pub fn new() -> MyServer {
  27. MyServer {
  28. routes: Vec::new(),
  29. }
  30. }
  31.  
  32. fn route<T: 'static + Fn(server::Request, server::Response)>(&mut self, verb: method::Method, uri: &str, handler: T) {
  33. self.routes.push( ( verb, uri.to_string(),Box::new(handler)) )
  34. }
  35.  
  36. pub fn serve(&mut self) {
  37. server::Server::http("127.0.0.1:8080").unwrap()
  38. .handle( MyHandler {routes: Mutex::new(self.routes) } ).unwrap();
  39. }
  40. }
  41.  
  42. fn main() {
  43. let mut c = MyServer::new().serve();
  44. }
  45.  
  46. 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]
  47. --> src/main.rs:17:6
  48. |>
  49. 17 |> impl server::Handler for MyHandler {
  50. |> ^^^^^^^^^^^^^^^
  51. note: `for<'r, 'r, 'r> std::ops::Fn(hyper::server::Request<'r, 'r>, hyper::server::Response<'r>) + 'static` cannot be sent between threads safely
  52. 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>`
  53. 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>)`
  54. 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>)>`
  55. 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>)>`
  56. 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>)>`
  57. 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>)>>`
  58. note: required because it appears within the type `MyHandler`
  59. note: required by `hyper::server::Handler`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement