Hacker News new | ask | show | jobs
by lobster_johnson 3400 days ago
I was surprised that Rust actually did it the way it is now (i.e. no implicit bounds). Article says accessing the map arg's methods will fail, but isn't the entire argument itself invalid by definition? You can't instantiate the hash map without validating that K and V do implement those traits.
1 comments

In the standard library today, there's no bounds on `K` on the definition of HashMap, only on the impl block containing its methods. This sort of makes HashMap a bad example for this code block; you're right that if the bounds were on the definition instead of the impl, the argument itself would be invalid.
I think it becomes useful only if whatever struct expects some extra level of behavior from the types. Basically any time a struct or a trait is coupled with another trait or needs a particular marker/lifetime to function I find myself repeating the bounds over and over.

For example in gfx-rs it might be repeating the gfx::Resources or gfx::Factory trait bounds.