Last active
April 12, 2017 08:58
-
-
Save MrSpock/d227cf06618b301f33936e6f55b6696b to your computer and use it in GitHub Desktop.
lifetime-fight-001
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
//=========== attempt 1 ============= | |
trait Handler<'a> { | |
fn handle(self, String) -> &'a str; | |
} | |
#[derive(Debug)] | |
struct TestHandle { | |
uri: String, | |
} | |
impl<'a> Handler<'a> for TestHandle { | |
fn handle(self, s: String) -> &'a str { | |
format!("via {}", s) | |
} | |
} | |
struct A<S> | |
where S: Handler | |
{ | |
name: String, | |
handler: Box<S>, | |
} | |
//error[E0106]: missing lifetime specifier | |
// --> src/main.rs:18:14 | |
// | | |
//18 | where S: Handler | |
// | ^^^^^^^ expected lifetime parameter | |
// | |
//error: aborting due to previous error | |
//===== attempt 2 ============= | |
struct A<S> | |
where S: Handler<'a> | |
{ | |
name: String, | |
handler: Box<S>, | |
} | |
//Error: | |
//error[E0261]: use of undeclared lifetime name `'a` | |
// --> src/main.rs:18:22 | |
// | | |
//18 | where S: Handler<'a> | |
// | ^^ undeclared lifetime | |
error: aborting due to previous error | |
// attempt 3 =============== | |
struct A<'a, S> | |
where S: Handler<'a> | |
{ | |
name: String, | |
handler: Box<S>, | |
} | |
//error[E0392]: parameter `'a` is never used | |
// --> src/main.rs:17:10 | |
// | | |
//17 | struct A<'a, S> | |
// | ^^ unused type parameter | |
// | | |
// = help: consider removing `'a` or using a marker such as `std::marker::PhantomData` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment