Skip to content

libcore: add str::first, str::split_first, str::last and str::split_last methods#89603

Closed
eduardosm wants to merge 2 commits intorust-lang:masterfrom
eduardosm:str-first-last
Closed

libcore: add str::first, str::split_first, str::last and str::split_last methods#89603
eduardosm wants to merge 2 commits intorust-lang:masterfrom
eduardosm:str-first-last

Conversation

@eduardosm
Copy link
Copy Markdown
Contributor

These methods are equivalent to their slice ([T]) counterparts.

If this PR is accepted, I will create a tracking issue and update the issue value accordingly.

@rust-highfive
Copy link
Copy Markdown
Contributor

r? @dtolnay

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 6, 2021
@camsteffen
Copy link
Copy Markdown
Contributor

I would add _char to the names. A str is [u8], not [char]. Consider chars is not named iter.

@jfrimmel
Copy link
Copy Markdown
Contributor

jfrimmel commented Oct 6, 2021

I would add _char to the names. A str is [u8], not [char].

I disagree. Mentally a str is a "list" of characters, that only happens to be stored as bytes. If somebody needs to get the first byte, s.as_bytes().first() (etc.) can be used.

Consider chars is not named iter.

Yes, but there are other iterators (bytes(), char_indices()) as well.

@ChrisDenton
Copy link
Copy Markdown
Member

Mentally a str is a "list" of characters,

What are "characters" in this sense? It could mean "scalar values" (i.e. the atomic unit of Unicode). Or it could mean what the user perceives as characters (e.g. extended grapheme clusters). While the standard library currently only supports the former, it's reasonable for third party crates to add support for the latter. I'm uncertain what these names should be but I think there is at least a reason to prefer unambiguous naming.

I definitely support adding these functions, whatever they are named.

@jfrimmel
Copy link
Copy Markdown
Contributor

jfrimmel commented Oct 8, 2021

To clarify: I think, that the _char-suffix is not relevant, but others might disagree. But sleeping over it, I have to admit, that of course clear names are always good.

So, maybe my first comment was a little bit to harsh.

@eduardosm
Copy link
Copy Markdown
Contributor Author

I like the idea of adding the _char suffix to the function names. I have pushed a new commit adding that

@the8472 the8472 added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Oct 11, 2021
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 31, 2021
Copy link
Copy Markdown
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Could you provide some more detail on how you're planning to use these methods? Is there maybe an example of real-world open source code you could link to that would benefit from having these?

@dtolnay dtolnay added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 1, 2021
@crlf0710
Copy link
Copy Markdown
Member

@eduardosm Ping from triage, any updates on this?

@eduardosm
Copy link
Copy Markdown
Contributor Author

Could you provide some more detail on how you're planning to use these methods? Is there maybe an example of real-world open source code you could link to that would benefit from having these?

I missed these methods while I was writing a lexer, although its code is not public yet. There is also #48731.

@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 30, 2022
@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 27, 2022
@JohnCSimon
Copy link
Copy Markdown
Member

@eduardosm
Triage: I'm closing this due to inactivity. Please reopen when you are ready to continue with this. Thanks for your contribution
@rustbot label: +S-inactive

@JohnCSimon JohnCSimon closed this Feb 27, 2022
@rustbot rustbot added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label Feb 27, 2022
@camsteffen
Copy link
Copy Markdown
Contributor

Now that we have an accepted ACP for this, maybe we can we reopen this PR?

@reddevilmidzy
Copy link
Copy Markdown
Member

@eduardosm I tried to reopen this PR, but I cannot open it because the repository has been deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.