I'm not sure how much this overlaps with what you're proposing, but
regarding hashmaps:

I'm hoping to see overloadable IndexAddAssign and IndexMulAssign and
friends someday, and the notion of neutral element differs between them,
e.g.:

    impl<K,V:Zero> HashMap<K,V> {
        ... IndexAddAssign ...
    }
    impl<K,V:One> HashMap<K,V> {
        ... IndexMulAssign ...
    }

So I guess the question I'm asking is, is Zero universal enough to make it
a library convention?

Mitch



On Thu, May 30, 2013 at 2:56 AM, Niko Matsakis <[email protected]> wrote:

> Another example is in Hashmaps, where we offer two variants on the
> "find-or-insert" pattern:
>
>     fn find_or_insert(&mut self, K, V) -> Option<&V>
>     fn find_or_insert_with(&mut self, K, &fn(&K) -> V) -> Option<&V>
>
> Under my proposal there would just be:
>
>     fn find_or_insert(&mut self, K, &fn(&K) -> V) -> Option<&mut V>
>     fn find_or_insert_zero(&mut self, K) -> Option<&mut V> // where V:Zero
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to