Skip to content

Instantly share code, notes, and snippets.

@chrisdavies
Created October 28, 2014 14:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisdavies/9d9c0aff6229ef1d3eef to your computer and use it in GitHub Desktop.
Save chrisdavies/9d9c0aff6229ef1d3eef to your computer and use it in GitHub Desktop.
Rust - lifetime constraint and generic constraint on a struct
use std::io::Writer;
// This specifies lifetime constraint of 'a
// Type W must implement the Writer trait
// Type W has the lifetime 'a (the same as the related struct instance)
pub struct Foo<'a, W: 'a + Writer> {
writer: &'a mut W
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment