Hi Alex,

This is Issue #5121, I believe. That error message is certainly
confusing but basically it's a bug and known limitation. I hope to
lift it...soonish as part of the fix for finishing the work on
lifetime syntax (#4846).


Niko


On Fri, Sep 06, 2013 at 08:27:49PM +0100, Alex 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