mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
86721a4c90
Stabilize const `{integer}::from_str_radix` i.e. `const_int_from_str` This PR stabilizes the feature `const_int_from_str`. - ACP Issue: rust-lang/libs-team#74 - Implementation PR: rust-lang/rust#99322 - Part of Tracking Issue: rust-lang/rust#59133 API Change Diff: ```diff impl {integer} { - pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>; + pub const fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError>; } impl ParseIntError { - pub fn kind(&self) -> &IntErrorKind; + pub const fn kind(&self) -> &IntErrorKind; } ``` This makes it easier to parse integers at compile-time, e.g. the example from the Tracking Issue: ```rust env!("SOMETHING").parse::<usize>().unwrap() ``` could now be achived with ```rust match usize::from_str_radix(env!("SOMETHING"), 10) { Ok(val) => val, Err(err) => panic!("Invalid value for SOMETHING environment variable."), } ``` rather than having to depend on a library that implements or manually implement the parsing at compile-time. --- Checklist based on [Libs Stabilization Guide - When there's const involved](https://std-dev-guide.rust-lang.org/development/stabilization.html#when-theres-const-involved) I am treating this as a [partial stabilization](https://std-dev-guide.rust-lang.org/development/stabilization.html#partial-stabilizations) as it shares a tracking issue (and is rather small), so directly opening the partial stabilization PR for the subset (feature `const_int_from_str`) being stabilized. - [x] ping Constant Evaluation WG - [x] no unsafe involved - [x] no `#[allow_internal_unstable]` - [ ] usage of `intrinsic::const_eval_select` rust-lang/rust#124625 in `from_str_radix_assert` to change the error message between compile-time and run-time - [ ] [rust-labg/libs-api FCP](https://github.com/rust-lang/rust/pull/124941#issuecomment-2207021921) |
||
---|---|---|
.. | ||
async_iter | ||
ffi | ||
fmt | ||
hash | ||
io | ||
iter | ||
net | ||
num | ||
ops | ||
panic | ||
alloc.rs | ||
any.rs | ||
array.rs | ||
ascii.rs | ||
asserting.rs | ||
atomic.rs | ||
bool.rs | ||
cell.rs | ||
char.rs | ||
clone.rs | ||
cmp.rs | ||
const_ptr.rs | ||
convert.rs | ||
error.rs | ||
ffi.rs | ||
future.rs | ||
intrinsics.rs | ||
lazy.rs | ||
lib.rs | ||
macros.rs | ||
manually_drop.rs | ||
mem.rs | ||
nonzero.rs | ||
ops.rs | ||
option.rs | ||
panic.rs | ||
pattern.rs | ||
pin_macro.rs | ||
pin.rs | ||
ptr.rs | ||
result.rs | ||
simd.rs | ||
slice.rs | ||
str_lossy.rs | ||
str.rs | ||
task.rs | ||
time.rs | ||
tuple.rs | ||
unicode.rs | ||
waker.rs |