Skip to content

Instantly share code, notes, and snippets.

@MrSpock MrSpock/ltf.rs
Last active Apr 12, 2017

Embed
What would you like to do?
lifetime-fight-001
//=========== 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
You can’t perform that action at this time.