Skip to content

Instantly share code, notes, and snippets.

@Hoverbear
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hoverbear/ec5ae2510d228f6d4d43 to your computer and use it in GitHub Desktop.
Save Hoverbear/ec5ae2510d228f6d4d43 to your computer and use it in GitHub Desktop.
purge_from() for a file.
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.
}
});
}
@Hoverbear
Copy link
Author

   Compiling raft v0.0.1 (file:///Users/hoverbear/git/raft)
src/lib.rs:605:21: 605:25 error: cannot move out of borrowed content
src/lib.rs:605         let chars = self.log.chars();
                                   ^~~~
src/lib.rs:607:27: 607:31 error: cannot move out of borrowed content
src/lib.rs:607         chars.skip_while(|&opt| {
                                         ^~~~
src/lib.rs:607:28: 607:31 note: attempting to move value to here
src/lib.rs:607         chars.skip_while(|&opt| {
                                          ^~~
src/lib.rs:607:28: 607:31 help: to prevent the move, use `ref opt` or `ref mut opt` to capture value by reference
src/lib.rs:607         chars.skip_while(|&opt| {
                                          ^~~
error: aborting due to 2 previous errors

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