On 05/30/2013 04:56 AM, Niko Matsakis 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
> 
> Thoughts?

I like the idea of the closure, but (as a relative newcomer), how would
the Zero trait be specified? Wouldn't it require all HashMap's V's
implement Zero?

-- 
Tommy M. McGuire
mcgu...@crsr.net
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to