Commit f3e266e
Artem Kryvokrysenko
Relax constraint in hash_map::EntryRef insertion methods K: From<&Q> to &Q: Into<K>
Currently `EntryRef::or_insert*` methods have constraint `K: From<&Q>` which is
required to construct "owned" key from "borrowed" key during insertion operation.
Rust documentation recommends not to use `From` as trait constraint, and instead
prefer to use reversed `Into` trait constraint:
https://doc.rust-lang.org/std/convert/trait.From.html
> Prefer using Into over using From when specifying trait bounds on a generic
> function. This way, types that directly implement Into can be used as arguments as well.
Changing constraint `K: From<&Q>` to `&Q: Into<K>` extends support of insert operation
to additional cases where `K` does not implement trait `From<&Q>`, but `&Q` does implement
trait `Into<K>`.
**API compatibility**: `&Q: Into<K>` is a strict superset of `K: From<&Q>` (because of blanket
implementation https://doc.rust-lang.org/std/convert/trait.Into.html#impl-Into%3CU%3E-for-T),
so this change does not break existing hashbrown API compatibility; all existing code will work
with new trait constraints.1 parent b5b0655 commit f3e266e
1 file changed
+14
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4131 | 4131 | | |
4132 | 4132 | | |
4133 | 4133 | | |
4134 | | - | |
| 4134 | + | |
| 4135 | + | |
4135 | 4136 | | |
4136 | 4137 | | |
4137 | 4138 | | |
| |||
4164 | 4165 | | |
4165 | 4166 | | |
4166 | 4167 | | |
4167 | | - | |
| 4168 | + | |
| 4169 | + | |
4168 | 4170 | | |
4169 | 4171 | | |
4170 | 4172 | | |
| |||
4194 | 4196 | | |
4195 | 4197 | | |
4196 | 4198 | | |
4197 | | - | |
| 4199 | + | |
| 4200 | + | |
4198 | 4201 | | |
4199 | 4202 | | |
4200 | 4203 | | |
| |||
4225 | 4228 | | |
4226 | 4229 | | |
4227 | 4230 | | |
4228 | | - | |
| 4231 | + | |
| 4232 | + | |
4229 | 4233 | | |
4230 | 4234 | | |
4231 | 4235 | | |
| |||
4320 | 4324 | | |
4321 | 4325 | | |
4322 | 4326 | | |
4323 | | - | |
| 4327 | + | |
| 4328 | + | |
4324 | 4329 | | |
4325 | 4330 | | |
4326 | 4331 | | |
| |||
4368 | 4373 | | |
4369 | 4374 | | |
4370 | 4375 | | |
4371 | | - | |
| 4376 | + | |
| 4377 | + | |
4372 | 4378 | | |
4373 | 4379 | | |
4374 | 4380 | | |
| |||
4399 | 4405 | | |
4400 | 4406 | | |
4401 | 4407 | | |
4402 | | - | |
| 4408 | + | |
| 4409 | + | |
4403 | 4410 | | |
4404 | 4411 | | |
4405 | 4412 | | |
| |||
0 commit comments