Skip to content

Instantly share code, notes, and snippets.

@Sgeo
Created April 26, 2016 01:50
Show Gist options
  • Save Sgeo/6b823374aa48295f11e83e1bba65dcfc to your computer and use it in GitHub Desktop.
Save Sgeo/6b823374aa48295f11e83e1bba65dcfc to your computer and use it in GitHub Desktop.
trait ApplyLTable<'to> {
type Applied;
}
impl<'from, 'to, T: 'from+'to> ApplyLTable<'to> for &'from T {
type Applied = &'to T;
}
impl<'from, 'to, T: 'from+'to> ApplyLTable<'to> for &'from mut T {
type Applied = &'to mut T;
}
type ApplyLT<'lt, T> = <T as ApplyLTable<'lt>>::Applied;
trait Streamer {
type Item: for<'a> ApplyLTable<'a>;
fn next<'a>(&'a mut self) -> Option<ApplyLT<'a, Self::Item>>;
}
struct SelfStreaming;
impl Streamer for SelfStreaming {
type Item = &'static mut Self;
fn next<'a>(&'a mut self) -> Option<&'a mut Self> {
Some(self)
}
}
fn main() {
let mut foo = SelfStreaming;
foo.next();
foo.next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment