Oh, one other thing:

Your each() method does not obey the for protocol! When the callback returns false, you should abort iteration altogether. This presumably means you need to do the recursion in a helper method that itself returns bool so that you can detect when to carry on and when to abort.


Niko

Steve Jenson wrote:
On Thu, Dec 27, 2012 at 3:16 PM, Niko Matsakis <[email protected] <mailto:[email protected]>> wrote:

    I'm sorry for not replying more quickly, I was not checking e-mail
    over xmas break.  I do not know of any general problems with @ and
    borrowing.  In any event, this is a misdiagnosis.


No problem with reply timing.

    The problem is this: the declaration of iter looks like this:

        impl<K: Copy Eq Ord, V: Copy> RBMap<K, V>: iter::BaseIter<(&K,
    &V)>

    In the context of a type declaration, an & means `&self`, where
    `self` is the lifetime parameter associated with the
    type/impl/whatever (just as the impl has two type parameters K and
    V, it also has an implicit lifetime parameter `self`).  So, this
    declaration written out more explicitly would be:

    impl<K: Copy Eq Ord, V: Copy> RBMap<K, V>:
    iter::BaseIter<(&self/K, &self/V)>

    However, your method declaration is:

        pure fn each(&self, f: fn(&(&K, &V)) -> bool) { ... }

    In the context of a function declaration, & means "a fresh
    lifetime".  So this winds up being short for a declaration life this:

        pure fn each(&self, f: fn(&a/(&a/K, &a/V)) -> bool) { ... }

    However, the trait declares that `each` should have this type:

        pure fn each(&self, f: fn(&a/(&self/K, &self/V)) -> bool) { ... }

    So I think that if you change your declaraiton of `each()` to:

        pure fn each(&self, f: fn(&(&self/K, &self/V)) -> bool) { ... }

    It will work just fine.  I apologize for the cryptic error
    message.  Working on it.


Unfortunately not but a much more interesting set of error messages about lifetimes is coming out now: http://pastebin.com/SYwCw1ac

And here is a link to the each method again (I pushed this broken version to github so I can share the exact changes I made)

https://github.com/stevej/rustled/blob/master/red_black_tree.rs#L96

Thanks a bunch for all of your clarifying comments and blog posts.

Steve
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to