Skip to content

Instantly share code, notes, and snippets.

@jroesch
Created July 30, 2014 16:23
Show Gist options
  • Save jroesch/c94e7a005846f790e3b5 to your computer and use it in GitHub Desktop.
Save jroesch/c94e7a005846f790e3b5 to your computer and use it in GitHub Desktop.
bug.rs
use std::io::BufferedReader;
use std::io::File;
pub struct Data {
content: Box<Iterator<String>>
}
impl Iterator<String> for Data {
fn next(&mut self) -> Option<String> {
self.content.next()
}
}
fn new_data(file_name: &str) -> Data {
let path = Path::new(file_name);
let file = File::open(&path);
let mut reader = BufferedReader::new(file);
Data { content: box reader.lines().map(|str| str.unwrap()) }
}
fn main() {
let mut data = new_data("prelude.ob");
println!("{}", data.next())
}
@jroesch
Copy link
Author

jroesch commented Jul 30, 2014

I am using rustc 0.12.0-pre-nightly (5ebf4813a 2014-07-29 21:16:50 +0000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment