Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,8 @@ impl str {
/// 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

///
/// # Examples
///
/// Basic usage:
Expand Down Expand Up @@ -1281,6 +1283,15 @@ impl str {
///
/// assert_eq!(None, lines.next());
/// ```
///
/// An empty string returns no lines:
///
/// ```
/// let text = "";
/// let mut lines = text.lines();
///
/// assert_eq!(lines.next(), None);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn lines(&self) -> Lines<'_> {
Expand Down
Loading