Skip to content

Instantly share code, notes, and snippets.

@enricostano
Last active Oct 21, 2015
Embed
What would you like to do?
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

enricostano commented Oct 21, 2015

   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