-
Notifications
You must be signed in to change notification settings - Fork 14.1k
add note to lines docs about empty str behavior
#148912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
library/core/src/str/mod.rs
Outdated
| /// ending will return the same lines as an otherwise identical string | ||
| /// without a final line ending. | ||
| /// | ||
| /// An empty string returns no lines. |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay cool, updated
|
Sounds good -- agreed this is really useful to have as an explicit @bors r+ rollup |
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.
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.
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.
Rollup of 11 pull requests Successful merges: - #148505 (add larger test for `proc_macro` `FromStr` implementations) - #148752 (Constify `ManuallyDrop::take`) - #148757 (Constify `mem::take`) - #148855 (Error if an autodiff user does not set lto=fat) - #148912 (add note to `lines` docs about empty str behavior) - #148958 (Run codegen tests on a 32-bit target in PR CI) - #148994 (Abi compatibility test cleanup) - #148999 (Tweak Motor OS linker preset, fix `remote-test-server` for Motor OS) - #149004 (compiletest: Avoid race condition in file deletion) - #149008 (triagebot: remove jsha from notifications for rustdoc HTML) - #149010 (compiletest: Remove the "wasm32-bare" alias for `wasm32-unknown-unknown`) r? `@ghost` `@rustbot` modify labels: rollup
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.
Rollup of 11 pull requests Successful merges: - rust-lang/rust#148505 (add larger test for `proc_macro` `FromStr` implementations) - rust-lang/rust#148752 (Constify `ManuallyDrop::take`) - rust-lang/rust#148757 (Constify `mem::take`) - rust-lang/rust#148855 (Error if an autodiff user does not set lto=fat) - rust-lang/rust#148912 (add note to `lines` docs about empty str behavior) - rust-lang/rust#148958 (Run codegen tests on a 32-bit target in PR CI) - rust-lang/rust#148994 (Abi compatibility test cleanup) - rust-lang/rust#148999 (Tweak Motor OS linker preset, fix `remote-test-server` for Motor OS) - rust-lang/rust#149004 (compiletest: Avoid race condition in file deletion) - rust-lang/rust#149008 (triagebot: remove jsha from notifications for rustdoc HTML) - rust-lang/rust#149010 (compiletest: Remove the "wasm32-bare" alias for `wasm32-unknown-unknown`) r? `@ghost` `@rustbot` modify labels: rollup
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.
Rollup of 11 pull requests Successful merges: - rust-lang#148505 (add larger test for `proc_macro` `FromStr` implementations) - rust-lang#148752 (Constify `ManuallyDrop::take`) - rust-lang#148757 (Constify `mem::take`) - rust-lang#148855 (Error if an autodiff user does not set lto=fat) - rust-lang#148912 (add note to `lines` docs about empty str behavior) - rust-lang#148958 (Run codegen tests on a 32-bit target in PR CI) - rust-lang#148994 (Abi compatibility test cleanup) - rust-lang#148999 (Tweak Motor OS linker preset, fix `remote-test-server` for Motor OS) - rust-lang#149004 (compiletest: Avoid race condition in file deletion) - rust-lang#149008 (triagebot: remove jsha from notifications for rustdoc HTML) - rust-lang#149010 (compiletest: Remove the "wasm32-bare" alias for `wasm32-unknown-unknown`) r? `@ghost` `@rustbot` modify labels: rollup
This pull request adds a short note to the documentation for
str::linesthat 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.