-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Borrow #2433
Comments
Wouldn’t this turn Borrow into Cow?
… On May 7, 2018, at 10:05 AM, Soni L. ***@***.***> wrote:
std::borrow::Borrow has an extremely limited API, making the following painful:
struct Thing (u8, String);
let m: HashMap<Thing, String> = Default::default();
// how to access m with u8, &str, avoiding allocations?
I recommend changing Borrow into Borrow<'a, T> so you can do Borrow<'a, &'a str> for String and stuff.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
No? It just lets you have (u8, String) borrowing into (&u8, &str), so that both can be used to index a HashMap. It would also support |
Alternative: Key trait, with impl Key for T where T: Borrow. |
See the long thread on improving the Entry API via a new Query type. |
Key would be like, HashMap would take (also, link?) |
The I agree that |
surely we can change this in rust 2.0? the |
There will never be a Rust 2.0 afaik. |
Then consider writing a much more detailed proposal for what that solution is |
Afaik, all existing work towards doing this correctly lives in #1769 and https://internals.rust-lang.org/t/pre-rfc-abandonning-morals-in-the-name-of-performance-the-raw-entry-api/7043 so this can probably be closed in favor of continuing those discussions somewhere like internals. |
hmm nope, that isn't what I have/had in mind at all. |
The best way to discuss a proposal without writing a full RFC is by opening a pre-RFC thread in the internals forum (https://internals.rust-lang.org/). Just try it: You'll quickly notice that most Rust users who respond to github issues also read and post in the internals forum. Lately, various users have expressed their concern that new features that are added to the language should be vetted more throughly [1] [2]. This makes it even more important to follow the proper procedure for changes to the languages. Making a change without a proper RFC is impossible. But, as already mentioned, you can always create a pre-RFC in the internals forum, work out the details and then write the full RFC that follows the RFC template. |
Since this doesn't seem to be going anywhere, I'm closing this. See @MajorBreakfast's comment if you want to move forward with this. |
std::borrow::Borrow has an extremely limited API, making the following painful:
I recommend changing Borrow into Borrow<'a, T> so you can do
Borrow<'a, &'a str> for String
and derive it for multifield structs and stuff, reducing allocations all over the place.The text was updated successfully, but these errors were encountered: