-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Improve docs differentiating Borrow
and AsRef
#24163
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Notes from talking to @aturon borrow is used in things like hashmap, where you have a key, and the map needs to store the owned version, but you want to look things up by the borrowed version. for most types, you want T and &T. but for things that take slices, there's a few different slice types. Borrow is good for this it's more restrictive than asref, because the assumption is the borrow is the same wrt hashing or comparison: String, &str, and &String all hash to the same value. AsRef: you can get a different reference out of this. that's it. a conversion, not an equivalence. anything htat impls borrow should implement asref, but no blanket because of coherence |
These two traits are commonly confused. As such, explain the difference. Fixes rust-lang#24163
These two traits are commonly confused. As such, explain the difference. Fixes rust-lang#24163
These two traits are commonly confused. As such, explain the difference. Fixes rust-lang#24163 r? @aturon
These two traits are commonly confused. As such, explain the difference. Fixes rust-lang#24163 r? @aturon
Spawned of off #24140
The text was updated successfully, but these errors were encountered: