Skip to content

Instantly share code, notes, and snippets.

@enricostano
Last active October 21, 2015 10:56
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 enricostano/499597b9fe08d59a37b0 to your computer and use it in GitHub Desktop.
Save enricostano/499597b9fe08d59a37b0 to your computer and use it in GitHub Desktop.
Pipa
use std::io::{self, BufRead};
struct Item {
trigger: String,
value: String
}
impl Item {
fn new(trigger: String, value: String) -> Item {
Item { trigger: trigger, value: value }
}
}
fn trigger(index: &usize) -> String {
"o".to_string()
}
fn main() {
let stdin = io::stdin();
let lines = stdin.lock().lines().enumerate().map(|t| Item::new(trigger(&t.0), t.1.unwrap()));
}
@enricostano
Copy link
Author

   Compiling pipa v0.1.0 (file:///home/enrico/dev/pipa)
src/main.rs:15:6: 15:21 error: borrowed value does not live long enough
src/main.rs:15     &"o".to_string()
                    ^~~~~~~~~~~~~~~
src/main.rs:14:48: 16:2 note: reference must be valid for the lifetime 'a as defined on the block at 14:47...
src/main.rs:14 fn trigger<'a>(index: &'a usize) -> &'a String {
src/main.rs:15     &"o".to_string()
src/main.rs:16 }
src/main.rs:14:48: 16:2 note: ...but borrowed value is only valid for the block at 14:47
src/main.rs:14 fn trigger<'a>(index: &'a usize) -> &'a String {
src/main.rs:15     &"o".to_string()
src/main.rs:16 }
src/main.rs:20:77: 20:80 error: `t.0` does not live long enough
src/main.rs:20     let lines = stdin.lock().lines().enumerate().map(|t| Item::new(trigger(&t.0), &t.1.unwrap()));
                                                                                           ^~~
note: in expansion of closure expansion
src/main.rs:20:54: 20:97 note: expansion site
src/main.rs:20:17: 20:98 note: reference must be valid for the method call at 20:16...
src/main.rs:20     let lines = stdin.lock().lines().enumerate().map(|t| Item::new(trigger(&t.0), &t.1.unwrap()));
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:20:58: 20:97 note: ...but borrowed value is only valid for the scope of parameters for function at 20:57
src/main.rs:20     let lines = stdin.lock().lines().enumerate().map(|t| Item::new(trigger(&t.0), &t.1.unwrap()));
                                                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:20:84: 20:96 error: borrowed value does not live long enough
src/main.rs:20     let lines = stdin.lock().lines().enumerate().map(|t| Item::new(trigger(&t.0), &t.1.unwrap()));
                                                                                                  ^~~~~~~~~~~~
note: in expansion of closure expansion
src/main.rs:20:54: 20:97 note: expansion site
src/main.rs:20:17: 20:98 note: reference must be valid for the method call at 20:16...
src/main.rs:20     let lines = stdin.lock().lines().enumerate().map(|t| Item::new(trigger(&t.0), &t.1.unwrap()));
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:20:58: 20:97 note: ...but borrowed value is only valid for the block at 20:57
src/main.rs:20     let lines = stdin.lock().lines().enumerate().map(|t| Item::new(trigger(&t.0), &t.1.unwrap()));
                                                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 3 previous errors
Could not compile `pipa`.

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