Skip to content
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

Remove the return value of String::splice #44038

Closed
dtolnay opened this issue Aug 22, 2017 · 0 comments
Closed

Remove the return value of String::splice #44038

dtolnay opened this issue Aug 22, 2017 · 0 comments
Labels
A-collections Area: `std::collection` C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented Aug 22, 2017

As discussed in #32310, it is never necessary to look at the return value of String::splice. Applying the splice eagerly is always simpler and at least as efficient.

- fn splice<R>(&'a mut self, range: R, replace_with: &'b str) -> Splice<'a, 'b>;
+ fn splice<R>(&mut self, range: R, replace_with: &str);

With a return value:

  1. The String and the replacement str are in scope (start of 'a and 'b).
  2. Call splice, receive Splice struct.
  3. The String is exclusively borrowed and unusable.
  4. Process the replaced segment one char at a time.
  5. Drop the Splice struct.
  6. Drop the String and the replacement str (end of 'a and 'b, must happen after 5).

Without a return value;

  1. The String and the replacement str are in scope (start of 'a and 'b).
  2. Grab the soon replaced segment &s[range].
  3. The String is shared borrowed but otherwise usable.
  4. Process the soon replaced segment one char at a time or as an ordinary &str.
  5. Call splice which eagerly does the replace and returns ().
  6. Drop the String and the replacement str (end of 'a and 'b).
@shepmaster shepmaster added A-collections Area: `std::collection` C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Aug 25, 2017
alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 30, 2017
…lnay

Remove Splice struct return value from String::splice

The implementation is now almost identical to the one in the RFC.

Fixes rust-lang#44038
cc rust-lang#32310
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-collections Area: `std::collection` C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants