Advertisement
Guest User

Untitled

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