-
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
New str and String API #1253
Comments
|
Yep. I've started experimental implementations here for the moment, including Vec::splice. It doesn't compile perfectly though since it uses iterator input. But it's a nice real use of ExactSizeIterator. |
fwiw splice could be insert with Sufficient Generics. |
Relevant motivating example: https://github.com/servo/rust-url/blob/2be081e5fad04efc321e51f795aa2b95d21f4c10/src/parser.rs#L563 uses unsafe code to emulate a special case of splice. |
I'd like it if rather than adding new |
Ok. |
This sounds good to me bluss. |
Isn't |
Is there a reason not to have splice return an iterator over the removed values? That seems like a useful addition to have. The implementation would just need to replace the items one at a time, as each one is taken from the returned iterator, and fallback to drain-like behavior otherwise. |
rust-lang/rust#34771 added |
Proposed new
str
orString
APIString::insert_str(&mut self, index: usize, s: &str)
Just like
insert(&mut self, usize, char)
, but for a string piece. Insertion is inherently inefficient, but this impl will be better than the user having to create an entirely new String.String::splice<R>(&mut self, range: R, s: &str)
Combine
drain
andinsert_str
, allow both removing a range and replacing it with a new string in one operation. Removerange
, inserts
atrange.start
.str::repeat(&self, n: usize) -> String
Convenience to repeat a String. Will size the result correctly up front, so it's both simpler and faster than in-code iterator based solutions.
The text was updated successfully, but these errors were encountered: