Skip to content

Instantly share code, notes, and snippets.

@mike-engel
Created April 2, 2017 19:26
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 mike-engel/aa4c7c981107f0fedd626ec3667375c7 to your computer and use it in GitHub Desktop.
Save mike-engel/aa4c7c981107f0fedd626ec3667375c7 to your computer and use it in GitHub Desktop.
lifetimes are hard :(
#[macro_use]
extern crate lazy_static;
use std::fs::File;
use std::io::prelude::*;
use std::collections::HashSet;
use std::iter::FromIterator;
lazy_static! {
static ref PASSWORDS: HashSet<&'static str> = {
let mut f = File::open("common-passwords.txt")
.expect("There was a problem opening the list of passwords");
let mut file_contents = String::new();
f.read_to_string(&mut file_contents)
.expect("There was a problem reading the common passwords file");
HashSet::from_iter(file_contents.lines())
};
}
@mike-engel
Copy link
Author

Error output

error: `file_contents` does not live long enough
  --> src/lib.rs:18:28
   |
18 |         HashSet::from_iter(file_contents.lines())
   |                            ^^^^^^^^^^^^^ does not live long enough
19 |     };
   |     - borrowed value only lives until here
   |
   = note: borrowed value must be valid for the static lifetime...

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