-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: improve CString construction methods #912
Conversation
c400cd2
to
984a481
Compare
Where are the benchmarks? |
@mahkoh It's not about performance for now, though the changes widen possibilities for optimization in the future. |
You might not care about performance but I do.
The opposite is true. The optimizations possible with a &[u8] are a strict superset of the optimizations possible with an u8 Iterator. |
Given that |
The current CString::new performance can easily be improved by an order of magnitude.
Go for it. |
Then the same can be done for an implementation of |
@mahkoh I have no dog in this race (yet), but I find the tone of your comments here on this thread to be unnecessarily antagonistic. It is good and reasonable to inquire into the effect that this change has on performance, but we're all on the same team here. |
|
||
1. The `IntoBytes` trait does not seem wholly justified: it falls short of | ||
supporting `IntoIterator`, and has become yet another special-interest trait | ||
to care about when designing APIs producing string-like data. |
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.
Note that this trait was introduced but largely only as a temporary measure. With generic conversion traits this would be much less ad-hoc. The semi-current-plan is to leave IntoBytes
as #[unstable]
until we have conversion traits at which point we can switch to using those.
The two main sub-modules, `c_str` and `os_str`, have now had some time to bake in the standard library. This commits performs a sweep over the modules adding various stability tags. The following APIs are now marked `#[stable]` * `OsString` * `OsStr` * `OsString::from_string` * `OsString::from_str` * `OsString::new` * `OsString::into_string` * `OsString::push` (renamed from `push_os_str`, added an `AsOsStr` bound) * various trait implementations for `OsString` * `OsStr::from_str` * `OsStr::to_str` * `OsStr::to_string_lossy` * `OsStr::to_os_string` * various trait implementations for `OsStr` * `CString` * `CStr` * `NulError` * `CString::new` - this API's implementation may change as a result of rust-lang/rfcs#912 but the usage of `CString::new(thing)` looks like it is unlikely to change. Additionally, the `IntoBytes` bound is also likely to change but the set of implementors for the trait will not change (despite the trait perhaps being renamed). * `CString::from_vec_unchecked` * `CString::as_bytes` * `CString::as_bytes_with_nul` * `NulError::nul_position` * `NulError::into_vec` * `CStr::from_ptr` * `CStr::as_ptr` * `CStr::to_bytes` * `CStr::to_bytes_with_nul` * various trait implementations for `CStr` The following APIs remain `#[unstable]` * `OsStr*Ext` traits remain unstable as the organization of `os::platform` is uncertain still and the traits may change location. * `AsOsStr` remains unstable as generic conversion traits are likely to be rethought soon. The following APIs were deprecated * `OsString::push_os_str` is now called `push` and takes `T: AsOsStr` instead (a superset of the previous functionality).
IntoCString is promoted to proposed changes after meeting no objections as an ergonomic replacement for IntoBytes.
The generic conversion traits did land (and stabilize), meaning that many of the goals here have been resolved. The current constructors still work with Thanks @mzabaluev! |
Amend the methods available to construct a
CString
to improve composability and follow the conventions emerging elsewhere in the standard library.Rendered