Hey Everyone,
I'm new to rust but enjoying it a lot. I'm having trouble with the
following code example:
use std::hashmap::{HashMap, Map};
fn do_something<'input, M: Map<int, &'input str>> (key: int, map: &M){
match map.find(key){
Some(result) => println(fmt!("%s", result)),
None => println("no match")
};
}
fn main(){
let map : HashMap<int, &str> = HashMap::new();
map.insert(1, "one");
do_something(1, map);
}
This fails with a compilation error:
example.rs:4:44: 4:47 error: Illegal lifetime 'input: only 'self is allowed
as part of a type declaration
example.rs:4 fn do_something<'input, M: Map<int, &'input str>> (key: int,
map: &M){
Now, I'm probably misunderstanding a bunch of things here, firstly all the
example code I've seen out there uses the HashMap type directly rather than
the Map trait, is this idiomatic? Secondly, I'm still getting my head
around lifetimes and probably have this all muddled so any pointers there
would be welcome.
Thanks
Alex Good
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev