Skip to content

Commit 47585c9

Browse files
authored
Rollup merge of #148912 - msmoiz:main, r=scottmcm
add note to `lines` docs about empty str behavior 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.
2 parents e34ef24 + e628b05 commit 47585c9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

library/core/src/str/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,8 @@ impl str {
12511251
/// ending will return the same lines as an otherwise identical string
12521252
/// without a final line ending.
12531253
///
1254+
/// An empty string returns an empty iterator.
1255+
///
12541256
/// # Examples
12551257
///
12561258
/// Basic usage:
@@ -1281,6 +1283,15 @@ impl str {
12811283
///
12821284
/// assert_eq!(None, lines.next());
12831285
/// ```
1286+
///
1287+
/// An empty string returns an empty iterator:
1288+
///
1289+
/// ```
1290+
/// let text = "";
1291+
/// let mut lines = text.lines();
1292+
///
1293+
/// assert_eq!(lines.next(), None);
1294+
/// ```
12841295
#[stable(feature = "rust1", since = "1.0.0")]
12851296
#[inline]
12861297
pub fn lines(&self) -> Lines<'_> {

0 commit comments

Comments
 (0)