-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Introduce <&[_]>::split_off and <&str>::split_off #49173
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @withoutboats (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This seems nice to have 👍 |
+1-- I've written these a handful of times. I'd also like |
@cramertj I plan to make a separate PR for a more general "cutting" concept, with "anchored ranges". I'll probably do that at the end of the week. |
src/libcore/str/mod.rs
Outdated
|
||
#[inline] | ||
fn split_off_mut<'a>(self: &mut &'a mut Self, at: usize) -> &'a mut str { | ||
let (rest, split) = mem::replace(self, unsafe { from_utf8_unchecked_mut(&mut []) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is trivially safe since an empty string slice is UTF-8 by definition, but a comment to that effect would be nice here ;)
(Generally I think all uses of unsafe elimination blocks should come with a comment explaining the reason why it is safe.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally added the damn comment. :3
ping @withoutboats |
@withoutboats Ping. |
The implementation looks fine to me but the |
The method name here could be shadowed by We've also got methods like |
☔ The latest upstream changes (presumably #49698) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage! Can @withoutboats (or someone else from @rust-lang/libs) review this? |
Code looks good, I agree with Alex that the potential shadowing with the Vec API seems bad and it would be good to rename. In regard to @SimonSapin's point about the return type, I think this is just an example of the kinds of new APIs arbitrary_self_types enables. |
What should I rename them to? |
@nox How about: |
I would expect such a method to set |
@nox / @alexcrichton: It looks like the main blocker here is deciding on names for the new methods. How do you want to move forward with this? If this does essentially the same as existing |
I don't have a particular personal preference on name, but I do think it just needs to be different |
Ping from triage! What's the status of this? |
Indeed! |
Sure. |
How about |
Ping from triage @nox @alexcrichton! What we should do with this PR? |
I propose that we just pick one of the suboptimal names proposed for now and optimize it during stabilization; maybe we'll have better ideas by then? |
Also; I noticed that |
Can we say that explicitly in the docs somehow? "If you don't like this name, pop on over to #XXXXX and paint the bikeshed" |
@shepmaster SGTM 👍 |
Looks like this hasn't been updated in awhile so I'm going to close, but feel free to resubmit of course! I think @Centril's idea above makes sense to me too! |
I completely forgot this PR. I'm currently doing a crate for slices represented as a pair of start and end pointers (like |
No description provided.