Skip to content

impl FromIterator<char> for Box<str> - #70094

Closed
andersk wants to merge 1 commit into
rust-lang:masterfrom
andersk:boxed_str_from_iter
Closed

impl FromIterator<char> for Box<str>#70094
andersk wants to merge 1 commit into
rust-lang:masterfrom
andersk:boxed_str_from_iter

Conversation

@andersk

Copy link
Copy Markdown
Contributor

This is analogous to impl FromIterator<A> for Box<[A]> (#55843).

Fixes#65163.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @LukasKalbertodt

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 18, 2020
@andersk
anderskforce-pushed the boxed_str_from_iter branch 2 times, most recently from 73ea386 to 5500fcdCompareMarch 18, 2020 04:02

@LukasKalbertodtLukasKalbertodt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a reasonable addition to me. Thanks!

Please add four tests for the other four impls. And see my inline comment on the test.

Comment threadsrc/liballoc/tests.rs Outdated
These are analogous to impl FromIterator<A> for Box<[A]> (rust-lang#55843).
Fixesrust-lang#65163.
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
@andersk
anderskforce-pushed the boxed_str_from_iter branch from 26e3e08 to e355419CompareMarch 18, 2020 09:02
@andersk

Copy link
Copy Markdown
ContributorAuthor

Sure, now all five impls are tested.

@LukasKalbertodtLukasKalbertodt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@LukasKalbertodtLukasKalbertodt added the T-libs-api [DEPRECATED; DO NOT USE] label Mar 18, 2020
@LukasKalbertodt

LukasKalbertodt commented Mar 18, 2020

Copy link
Copy Markdown
Contributor

This PR adds the following stable impls:

  • impl<'a> FromIterator<&'a char> for Box<str>
  • impl<'a> FromIterator<&'a str> for Box<str>
  • impl<'a> FromIterator<Cow<'a, str>> for Box<str>
  • impl FromIterator<String> for Box<str>
  • impl FromIterator<char> for Box<str>

All these impls already exist for String. Thus, the implementation is always simply: iter.into_iter().collect::<String>().into_boxed_str(). We also already had impl FromIterator<A> for Box<[A]> in std for a long time. There was an attempt at this already in #65168, which was closed due to inactivity.


As I cannot start FCP merges, reassigning.

@LukasKalbertodt

Copy link
Copy Markdown
Contributor

r? @Amanieu

@andersk

Copy link
Copy Markdown
ContributorAuthor

Note: I saw in #40028 that @withoutboats regretted that the five String impls could not be generalized to a single impl<T> FromIterator<T> for String where String: Extend<T> due to backwards compatibility (it might overlap with impl FromIterator<Foo> for String for a custom type Foo). I believe the same concern prevents a similar simplification for Box<str>, but I figured I’d mention it in case my understanding is wrong.

@jonas-schievinkjonas-schievink added the relnotes Marks issues that should be documented in the release notes of the next release. label Mar 18, 2020
@jonas-schievinkjonas-schievink added this to the 1.44 milestone Mar 18, 2020
@Centril

Copy link
Copy Markdown
Contributor

As I cannot start FCP merges, reassigning.

You should send in a PR to https://github.com/rust-lang/team to fix that btw. :)

@Amanieu

Copy link
Copy Markdown
Member

@rfcbot fcp merge

@rfcbot

rfcbot commented Mar 18, 2020

Copy link
Copy Markdown

Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbotrfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Mar 18, 2020
@dtolnay

dtolnay commented Mar 18, 2020

Copy link
Copy Markdown
Member

I am not enthusiastic about this addition. I would prefer not to go any more in the direction of making Box<str> a fully fledged string type. I see it as a niche alternative representation for owned strings for use cases in which 2 words of size instead of 3 words matters for memory usage, such as a big intern table. In general I'd like users to reach for String when operating with owned strings, and use into_boxed_str if their use case demands the representation of a boxed str.

I'm fine with the necessary APIs for Box<str> as a niche string representation, including things like From<String> and Default. I'm less fine with growing more string-related surface area around Box<str> than that, like FromIterator, Extend, Add, etc. If someone wants to collect into an owned string and use Box<str> as the representation, I think it's fine to have them write collect::<String>().into_boxed_str() instead of collect::<Box<str>>().

@rfcbot concern is Box<str> a string or a niche string representation

@bors

bors commented Apr 2, 2020

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #70362) made this pull request unmergeable. Please resolve the merge conflicts.

@dtolnay

Copy link
Copy Markdown
Member

I don't know whether procedurally I should fcp close, but I see a 👍 on #70094 (comment) from Lukas who originally proposed the fcp and it doesn't seem like people are planning to make the opposite case so I'll go ahead and directly close the PR. We can reopen as needed if someone is interested in sticking up for the opposite point of view.

Thanks anyway @andersk!

@dtolnaydtolnay closed this Apr 3, 2020
@rfcbotrfcbot removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Apr 3, 2020
@crlf0710crlf0710 removed this from the 1.44 milestone Apr 27, 2020
@dtolnaydtolnay self-assigned this Mar 24, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

relnotesMarks issues that should be documented in the release notes of the next release.S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement std::iter::FromIterator<char> for Box<str>

10 participants

@andersk@rust-highfive@LukasKalbertodt@Centril@Amanieu@rfcbot@dtolnay@bors@crlf0710@jonas-schievink