-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Implemented FromStr
for CString
and TryFrom<CString>
for String
#130608
Conversation
rustbot has assigned @workingjubilee. Use |
This is a request to stabilize a trait, and as such needs a FCP from libs-api. |
Is anything required from my side now? |
No. You could choose to provide additional explanatory justification for why this should be accepted, if you wish, but it's not required. |
Then there's nothing to add, actually. It's all about usability of the |
#[inline] | ||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
Self::new(s) | ||
} |
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.
It might be good to explicitly document that this does not require a terminating NUL in the input, maybe something like
#[inline] | |
fn from_str(s: &str) -> Result<Self, Self::Err> { | |
Self::new(s) | |
} | |
/// Creates a new C-compatible string from a `&str`. | |
/// | |
/// The trailing 0 byte will be appended by this function. If the provided data | |
/// contains any 0 bytes in it, `Err(NulError)` will be returned. | |
#[inline] | |
fn from_str(s: &str) -> Result<Self, Self::Err> { | |
Self::new(s) | |
} |
or maybe just link to the docs for CString::new
.
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.
Added a short description with a link to the corresponding function, and also did the same for the backward conversion.
39b391d
to
3243cd9
Compare
@rfcbot merge |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
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.
Needs to use TryFrom
not TryInto
.
🔔 This is now entering its final comment period, as per the review above. 🔔 |
A squash is favorable. |
FromStr
/TryInto<String>
for CString
FromStr
for CString
and TryFrom<CString> for
String`
FromStr
for CString
and TryFrom<CString> for
String`FromStr
for CString
and TryFrom<CString>
for String
a0b4219
to
3025513
Compare
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
@bors r+ |
…workingjubilee Implemented `FromStr` for `CString` and `TryFrom<CString>` for `String` The motivation of this change is making it possible to use `CString` in generic methods with `FromStr` and `TryInto<String>` trait bounds. The same traits are already implemented for `OsString` which is an FFI type too.
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#130608 (Implemented `FromStr` for `CString` and `TryFrom<CString>` for `String`) - rust-lang#130635 (Add `&pin (mut|const) T` type position sugar) - rust-lang#130747 (improve error messages for `C-cmse-nonsecure-entry` functions) - rust-lang#131137 (Add 1.82 release notes) - rust-lang#131328 (Remove unnecessary sorts in `rustc_hir_analysis`) - rust-lang#131496 (Stabilise `const_make_ascii`.) - rust-lang#131706 (Fix two const-hacks) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#130608 - YohDeadfall:cstr-from-into-str, r=workingjubilee Implemented `FromStr` for `CString` and `TryFrom<CString>` for `String` The motivation of this change is making it possible to use `CString` in generic methods with `FromStr` and `TryInto<String>` trait bounds. The same traits are already implemented for `OsString` which is an FFI type too.
The motivation of this change is making it possible to use
CString
in generic methods withFromStr
andTryInto<String>
trait bounds. The same traits are already implemented forOsString
which is an FFI type too.