-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Clarify documentation for CStr
#113220
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
Clarify documentation for CStr
#113220
Conversation
r? @m-ou-se (rustbot has picked a reviewer for you, use r? to override) |
@rustbot label +A-docs |
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.
I like the idea of making these more specific but this shouldn't fudge what it means here.
library/core/src/ffi/c_str.rs
Outdated
/// Creates a C string wrapper from a byte slice that includes one or more | ||
/// nul bytes. |
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.
Strictly speaking, it is valid to call this on a byte slice with zero \0
present, because the slice describes a safe bound to search in. That makes this technically incorrect. And yes, you can say "but that's the error case", but that's the problem! There's a Result
!
In addition, this first line is shown first in many inline editor hints or row-by-row formatted lists and accordingly should be kept ultra-short, so I hesitate at making it so much longer. It's fine if you can't find a way to express that in fewer characters, though.
library/core/src/ffi/c_str.rs
Outdated
/// Creates a C string wrapper from a byte slice terminated by exactly one | ||
/// nul byte. |
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.
Same comment on length, though if it really does need to be this long that's okay.
library/core/src/ffi/c_str.rs
Outdated
@@ -197,8 +197,8 @@ impl CStr { | |||
/// | |||
/// This function will wrap the provided `ptr` with a `CStr` wrapper, which | |||
/// allows inspection and interoperation of non-owned C strings. The total | |||
/// size of the raw C string must be smaller than `isize::MAX` **bytes** | |||
/// in memory due to calling the `slice::from_raw_parts` function. | |||
/// size of the raw C string must be smaller than [`isize::MAX`] **bytes** |
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.
The phrase "raw C string" feels weird to me, I don't feel like this documentation adequately describes what it means. That's preexisting though so you don't have to fix it, just noticing.
r? workingjubilee |
* Better differentiate summaries for `from_bytes_until_nul` and `from_bytes_with_nul` * Add some links where they may be helpful
5d65fac
to
c94dc72
Compare
Okiedoke I tried to improve some of the things you mentioned, should be ready for another look @rustbot ready |
Thanks! @bors r+ rollup |
☀️ Test successful - checks-actions |
Finished benchmarking commit (d8bbef5): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 647.209s -> 650.497s (0.51%) |
This is a documentation change on libcore/libstd. That does affect metadata during regular compilation, but there's nothing we could do here until this is taken care of, and the single regression is fine if not noise. @rustbot label: +perf-regression-triaged |
from_bytes_until_nul
andfrom_bytes_with_nul