Skip to content

Instantly share code, notes, and snippets.

@zokier
Created January 6, 2014 11:46
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 zokier/8281688 to your computer and use it in GitHub Desktop.
Save zokier/8281688 to your computer and use it in GitHub Desktop.
fn is_printable_ascii(c: u8) -> bool {
c >= 0x20u8 && c < 0x7fu8
}
fn main() {
// why temporary variable needed?
// error: borrowed value does not live long enough
let test_data: ~[u8] = std::io::File::open(&Path::new("test_data")).read_to_end();
let _test_data_filtered: ~[u8] = test_data.iter()
// why double deref?
// error: mismatched types: expected `u8` but found `&&u8` (expected u8 but found &-ptr)
.filter(|c| is_printable_ascii(**c))
// why this is needed?
// error: mismatched types: expected `~[u8]` but found `~[&u8]` (expected u8 but found &-ptr)
.map(|x| *x)
.to_owned_vec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment