Created
July 20, 2015 11:04
-
-
Save andor44/79aca5a802fcf8e5aa7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use rustorm::pool::Platform; | |
// use rustorm::database::Database as DB; | |
use rustorm::database::Database; | |
use rustful::{Context, Response, Handler}; | |
// type Database = DB + Sync; | |
pub struct Api { | |
db: Platform, | |
} | |
impl<'a> Api { | |
pub fn new(db: Platform) -> Api { | |
Api { | |
db: db, | |
} | |
} | |
pub fn handle(&self, handler: fn(&Database, Context, Response)) -> ApiHandler<'a> { | |
ApiHandler { | |
handler: handler, | |
db: self.db.as_ref(), | |
} | |
} | |
} | |
pub struct ApiHandler<'a> { | |
handler: fn(&Database, Context, Response), | |
db: &'a Database, | |
} | |
impl<'a> Handler for ApiHandler<'a> { | |
fn handle_request(&self, context: Context, response: Response) { | |
let handler = self.handler; | |
handler(self.db, context, response); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Compiling felix v0.1.0 (file:///home/andor/projects/felix) | |
src/api.rs:34:1: 39:2 error: the trait `core::marker::Sync` is not implemented for the type `rustorm::database::Database + 'a` [E0277] | |
src/api.rs:34 impl<'a> Handler for ApiHandler<'a> { | |
src/api.rs:35 fn handle_request(&self, context: Context, response: Response) { | |
src/api.rs:36 let handler = self.handler; | |
src/api.rs:37 handler(self.db, context, response); | |
src/api.rs:38 } | |
src/api.rs:39 } | |
src/api.rs:34:1: 39:2 help: run `rustc --explain E0277` to see a detailed explanation | |
src/api.rs:34:1: 39:2 note: `rustorm::database::Database + 'a` cannot be shared between threads safely | |
src/api.rs:34 impl<'a> Handler for ApiHandler<'a> { | |
src/api.rs:35 fn handle_request(&self, context: Context, response: Response) { | |
src/api.rs:36 let handler = self.handler; | |
src/api.rs:37 handler(self.db, context, response); | |
src/api.rs:38 } | |
src/api.rs:39 } | |
src/api.rs:34:1: 39:2 error: the type `api::ApiHandler<'a>` does not fulfill the required lifetime | |
src/api.rs:34 impl<'a> Handler for ApiHandler<'a> { | |
src/api.rs:35 fn handle_request(&self, context: Context, response: Response) { | |
src/api.rs:36 let handler = self.handler; | |
src/api.rs:37 handler(self.db, context, response); | |
src/api.rs:38 } | |
src/api.rs:39 } | |
note: type must outlive the static lifetime | |
error: aborting due to 2 previous errors | |
Could not compile `felix`. | |
To learn more, run the command again with --verbose. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment