Additions/improvements for doc examples.#42749
Conversation
src/libstd/ffi/c_str.rs
Outdated
There was a problem hiding this comment.
How about adding an example for the invalid Unicode case? Either way is definitely wouldn't return Cow::Borrowed it would return Cow::Owned.
There was a problem hiding this comment.
I figured it'd be undefined behavior to create a string w/ invalid unicode, as your comment here.
Either way is definitely wouldn't return Cow::Borrowed it would return Cow::Owned.
Yep, good catch, I'll change that
There was a problem hiding this comment.
I figured it'd be undefined behavior to create a string w/ invalid unicode
Strings and strs have to contain valid UTF-8 but CStrings and Cstrs are just sequences of any none null bytes. The following example would be fine:
use std::borrow::Cow;
use std::ffi::CStr;
let c_str = CStr::from_bytes_with_nul(b"foo\xc3\0").unwrap();
assert_eq!(c_str.to_string_lossy(), "foo�");It would also be more correct to say "(in)valid UTF-8" rather than "(in)valid unicode" in this case.
There was a problem hiding this comment.
It might be worth borrowing from the example in String::from_utf8_lossy, which uses the input string b"Hello \xF0\x90\x80World" to demonstrate the replacement.
|
Looks good, other than the discussion surrounding |
098c0ef to
4a408c6
Compare
Fixed the failing doc test and updated the |
4a408c6 to
2aeebbb
Compare
src/libstd/ffi/c_str.rs
Outdated
There was a problem hiding this comment.
Could you change this to ```no_run? Also the some_external_function(raw) on line 307 should be some_extern_function(raw).
There was a problem hiding this comment.
I think I'll get linker errors upon building, right?
There was a problem hiding this comment.
Latest force push addresses the typo, good catch
There was a problem hiding this comment.
@frewsxcv Currently no_run (and compile_fail as well) will stop after analysis. It won't even run codegen.
97de688 to
94b09dd
Compare
|
Changed |
|
☔ The latest upstream changes (presumably #42716) made this pull request unmergeable. Please resolve the merge conflicts. |
94b09dd to
58bbe1d
Compare
|
Rebased, addressed merge conflicts |
|
@bors r+ |
|
📌 Commit 58bbe1d has been approved by |
|
@bors rollup |
…QuietMisdreavus Additions/improvements for doc examples. None
No description provided.