Skip to content

Conversation

@msmoiz
Copy link

@msmoiz msmoiz commented Nov 13, 2025

This pull request adds a short note to the documentation for str::lines that describes the behavior of the resulting iterator when called on an empty string. I tripped over this a few days ago because I thought (incorrectly) that the iterator would return a single line with an empty string. I don't doubt that the actual behavior (return no lines) is the correct behavior, but in the absence of explicit documentation describing it, I came to the wrong conclusion about it and maybe others will too. If this is so obvious as to be not worth including, I'm happy to withdraw the pull request! Thanks for taking a look.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 13, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 13, 2025

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

/// ending will return the same lines as an otherwise identical string
/// without a final line ending.
///
/// An empty string returns no lines.
Copy link
Member

Choose a reason for hiding this comment

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

imho, "no lines" feels not obvious what does that mean, like, would it be better to have wording like "returns None"?

Copy link
Author

Choose a reason for hiding this comment

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

Hmm, I think that might be a bit confusing since the method itself returns a Lines object instead of an Option and saying "returns None" makes it sound like it returns an Option. A few possible alternatives:

  • "An empty string returns an empty iterator"
  • "Returns an empty iterator when called on an empty string"
  • "Empty strings produce no lines"

Copy link
Member

Choose a reason for hiding this comment

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

Ah, sure it's an iterator

Empty iterator instead None then, should be clear enough

Copy link
Author

Choose a reason for hiding this comment

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

Okay cool, updated

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants