Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ... I have a BufferedReader giving me file and a HashMap giving me map
- for line in file.lines() {
- let s = line.unwrap();
- // Sample: "appadmin....................................." dots are whitespace and should get trimmed off the keys
- if s.starts_with("<FLTR>") {
- let user = s.slice(97, 142).trim();
- if map.contains_key(&user) {
- println!("found!");
- }
- }
- }
- // Gives the following:
- D:\Rust\ARLogFilter\src\testing.rs:17:21: 17:22 error: `s` does not live long enough
- D:\Rust\ARLogFilter\src\testing.rs:17 let user = s.slice(97, 142).trim();
- ^
- D:\Rust\ARLogFilter\src\testing.rs:5:11: 23:2 note: reference must be valid for the block at 5:10...
- D:\Rust\ARLogFilter\src\testing.rs:5 fn main() {
- D:\Rust\ARLogFilter\src\testing.rs:6 let mut map = HashMap::new();
- D:\Rust\ARLogFilter\src\testing.rs:7 map.insert("appadmin", "foo");
- D:\Rust\ARLogFilter\src\testing.rs:8 map.insert("Remedy Application Service", "bar");
- D:\Rust\ARLogFilter\src\testing.rs:9
- D:\Rust\ARLogFilter\src\testing.rs:10 // input file
- ...
- D:\Rust\ARLogFilter\src\testing.rs:13:27: 22:3 note: ...but borrowed value is only valid for the block at 13:26
- D:\Rust\ARLogFilter\src\testing.rs:13 for line in file.lines() {
- D:\Rust\ARLogFilter\src\testing.rs:14 let s = line.unwrap();
- D:\Rust\ARLogFilter\src\testing.rs:15 // Sample: "appadmin....................................." dots are whitespace and should get trimmed off the keys
- D:\Rust\ARLogFilter\src\testing.rs:16 if s.starts_with("<FLTR>") {
- D:\Rust\ARLogFilter\src\testing.rs:17 let user = s.slice(97, 142).trim();
- D:\Rust\ARLogFilter\src\testing.rs:18 if map.contains_key(&user) {
- ...
- error: aborting due to previous error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement