Created
October 31, 2016 02:11
-
-
Save tarcieri/88de37bb355cedbd910e9d3251a96b36 to your computer and use it in GitHub Desktop.
Generics, traits, and lifetimes, oh my!
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
pub trait MyTrait<'a> { | |
fn foo(n: &'a i32); | |
} | |
struct Derp; | |
impl<'a> MyTrait<'a> for Derp { | |
fn foo(n: &'a i32) { | |
} | |
} | |
struct Herp<'a, T> where T: MyTrait<'a> { | |
derp: T | |
} | |
fn main() { | |
Herp::<Derp>::foo(42); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a rather contrived example, but I think it captures my current problem.
If I do
struct Herp<T>
I get:If I do
struct Herp<'a, T>
I get: