Rust newbie here as well, trying to develop an intuition for these things
myself :-) Off the top of my head - you are saying the map holds entries
whose lifetime is 'input; but there's no guarantee that the map lifetime
itself wouldn't be longer than that. Try saying &'input M instead of &M and
see how it goes.

Oren.


On Fri, Sep 6, 2013 at 10:27 PM, Alex <[email protected]> wrote:

> 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
>
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to