Last active
August 29, 2015 14:15
-
-
Save Hoverbear/ec5ae2510d228f6d4d43 to your computer and use it in GitHub Desktop.
purge_from() for a file.
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
fn move_to(&mut self, line: u64) { | |
let mut lines_read = 0; | |
let chars = self.log.chars(); | |
// Go until we've reached `from` new lines. | |
chars.skip_while(|&opt| { | |
match opt { | |
Ok(val) => { | |
if val == '\n' { | |
lines_read += 1; | |
if lines_read == line { | |
false // At right location. | |
} else { | |
true // Not done yet, more lines to go. | |
} | |
} else { | |
true // Not a new line. | |
} | |
}, | |
_ => false // At EOF. Nothing to purge. | |
} | |
}); | |
} |
Author
Hoverbear
commented
Feb 14, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment