Last active
August 29, 2015 13:57
-
-
Save jroweboy/9827618 to your computer and use it in GitHub Desktop.
lifetimes
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
struct.rs:19:9: 21:10 error: cannot infer an appropriate lifetime due to conflicting requirements | |
struct.rs:19 |Request| -> Response { | |
struct.rs:20 Response { data: self.database.to_owned() } | |
struct.rs:21 } | |
struct.rs:18:56: 22:6 note: first, the lifetime cannot outlive the block at 18:55... | |
struct.rs:18 fn index<'b>(&'b self) -> 'a |Request| -> Response { | |
struct.rs:19 |Request| -> Response { | |
struct.rs:20 Response { data: self.database.to_owned() } | |
struct.rs:21 } | |
struct.rs:22 } | |
struct.rs:19:9: 21:10 note: ...so that closure does not outlive its stack frame | |
struct.rs:19 |Request| -> Response { | |
struct.rs:20 Response { data: self.database.to_owned() } | |
struct.rs:21 } | |
struct.rs:18:56: 22:6 note: but, the lifetime must be valid for the lifetime &'a as defined on the block at 18:55... | |
struct.rs:18 fn index<'b>(&'b self) -> 'a |Request| -> Response { | |
struct.rs:19 |Request| -> Response { | |
struct.rs:20 Response { data: self.database.to_owned() } | |
struct.rs:21 } | |
struct.rs:22 } | |
struct.rs:19:9: 21:10 note: ...so that types are compatible (expected `'a |Request| -> Response` but found `|Request| -> Response`) | |
struct.rs:19 |Request| -> Response { | |
struct.rs:20 Response { data: self.database.to_owned() } | |
struct.rs:21 } | |
error: aborting due to previous error |
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
struct Context<'a> { | |
database: &'a str, | |
} | |
struct Router<'a> { | |
route : 'a |Request| -> Response, | |
} | |
struct Request { | |
url: ~str, | |
} | |
struct Response { | |
data: ~str, | |
} | |
impl<'a> Context<'a> { | |
fn index<'b>(&'b self) -> 'a |Request| -> Response { | |
|Request| -> Response { | |
Response { data: self.database.to_owned() } | |
} | |
} | |
} | |
fn main() { | |
let x = Context { database : "Hello!" }; | |
let t = Request { url : ~"localhost" }; | |
let r = Router { route: x.index() }; | |
println!("route: {}", (r.route)(t).data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment