Skip to content

Instantly share code, notes, and snippets.

@Nemikolh
Forked from anonymous/playground.rs
Last active August 29, 2015 14:25
Show Gist options
  • Save Nemikolh/ac9f2a534a504ba5b6d5 to your computer and use it in GitHub Desktop.
Save Nemikolh/ac9f2a534a504ba5b6d5 to your computer and use it in GitHub Desktop.
Box<Iterator<Item=&Trait>>
use std::slice::Iter;
trait Test {
fn hello(&self);
}
impl Test for i32 {
fn hello(&self) {
println!("i32 {}", self);
}
}
struct TestIter<'a, T: 'a> {
it: Iter<'a, T>,
}
impl<'a, T> Iterator for TestIter<'a, T>
where T: Test + 'a
{
type Item = &'a Test;
fn next(&mut self) -> Option<Self::Item> {
self.it.next().map(|i| i as &Test)
}
}
impl<'a, T> TestIter<'a, T> {
fn new(it: Iter<'a, T>) -> TestIter<'a, T> {
TestIter {
it: it
}
}
}
enum Tata<'b> {
Shipo,
Lata(Box<Iterator<Item=&'b Test> + 'b>)
}
fn test<'b>(test: &'b [i32]) -> Tata {
//let a: Iter<'b, i32> = test.iter();
//let b: TestIter<'b, i32> = TestIter::<'b, i32>::new(a);
Tata::Lata(Box::new(TestIter::<'b, i32>::new(test.iter())) as Box<Iterator<Item=&'b Test>>)
}
fn main() {
let a = [1, 2, 3i32];
let b = Tata::Shipo;
match test(&a) {
Tata::Lata(i) => {
for t in i {
t.hello();
}
},
_ => (),
}
()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment