So that solves the first error, now I have something like the following
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: &'input M){
Which is weird because this isn't a type devlaration right? Anyway,
putting 'self as the lifetime (despite that making no sense) gives me this:
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1,::rt::backtrace to get
further details and report the results to github.com/mozilla/rust/issues
So I guess I'll go and report that.
^~~
Removing the 'input lifetime on str (which also doesn't really make
sense to do but I thought I would try), results in
example.rs:4:36: 4:40 error: Illegal anonymous lifetime: anonymous
lifetimes are not permitted here
example.rs:4 fn do_something<'input, M: Map<int, &str>> (key: int,
map: &'input M){
Any other ideas?
Thanks
Alex
On Mon 09 Sep 2013 18:14:50 BST, Oren Ben-Kiki wrote:
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]
<mailto:[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 <http://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] <mailto:[email protected]>
https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev