Repository navigation
Tracking Issue for int_from_ascii #134821
Copy link
Copy link
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
Feature gate: #![feature(int_from_ascii)]
This is a tracking issue for int_from_ascii, providing equivalent methods to {usize,u8,u16,u32,u64,u128,isize,i8,i16,i32,i64,i128}::from_str() and from_str_radix() that allow working directly on byte slices, in order to skip UTF-8 validation.
Public API
For each integer type X (usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128):
// core::num
impl X {
pub const fn from_ascii_bytes<T>(src: T) -> Result<X, ParseIntError>
where
T: [const] AsRef<[u8]> + [const] core::marker::Destruct;
pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32) -> Result<X, ParseIntError>
where
T: [const] AsRef<[u8]> + [const] core::marker::Destruct;
}
impl NonZero<X> {
pub const fn from_ascii_bytes<T>(src: T) -> Result<Self, ParseIntError>
where
T: [const] AsRef<[u8]> + [const] core::marker::Destruct;
pub const fn from_ascii_bytes_radix<T>(src: T, radix: u32) -> Result<Self, ParseIntError>
where
T: [const] AsRef<[u8]> + [const] core::marker::Destruct;
}Originally with src: &[u8]
// core::num
impl X {
pub const fn from_ascii(src: &[u8]) -> Result<X, ParseIntError>;
pub const fn from_ascii_radix(src: &[u8], radix: u32) -> Result<X, ParseIntError>;
}
impl NonZero<X> {
pub const fn from_ascii(src: &[u8]) -> Result<Self, ParseIntError>;
pub const fn from_ascii_radix(src: &[u8], radix: u32) -> Result<Self, ParseIntError>;
}Steps / History
- Abandoned implementation: Implement int_from_ascii_radix #105206
- API change proposal: Add from_bytes_radix function libs-team#469
- Implementation for
T: Implementint_from_ascii(#134821) #134824 - Implementation for
NonZero<T>: feat: Implementint_from_asciiforNonZero<T>#152267 -
from_ascii->from_ascii_bytesandsrc: &[u8]->src: impl AsRef<[u8]>: feat: Update method signature of int_from_ascii #159554 - Stabilization PR: Stabilize
int_from_ascii#163696
Unresolved Questions
- Stabilize Tracking Issue for
nonzero_from_str_radix#152193 first
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Activity
niklasf commentedon Dec 27, 2024
Opened PR #134824 with an implementation.
Implement `int_from_ascii` (rust-lang#134821)
Implement `int_from_ascii` (rust-lang#134821)
Auto merge of rust-lang#134824 - niklasf:int_from_ascii, r=<try>
Auto merge of rust-lang#134824 - niklasf:int_from_ascii, r=ibraheemdev
Auto merge of rust-lang#134824 - niklasf:int_from_ascii, r=ibraheemdev
Implement `int_from_ascii` (rust-lang#134821)
Squashed 'library/' changes from 78fc550..b522de4
Implement `int_from_ascii` (rust-lang#134821)
Squashed 'library/' changes from 78fc550..b522de4
Implement `int_from_ascii` (rust-lang#134821)
Squashed 'library/' changes from 78fc550..0b9e7db
Squashed 'library/' changes from 78fc550..0b9e7db
91 remaining items
sorairolake commentedon Feb 7, 2026
@niklasf Could you please update #134821 (comment) after #152267 is merged?
The current version only mentions primitive integer types, so I think the beginning description, the Public API section, and the Steps / History section should be updated.
Examples:
niklasf commentedon Feb 7, 2026
Thanks. I think that means #152193 should be stabilized first, so we don't end up with
NonZero<T>::from_ascii_radix()without a matchingNonZero<T>::from_str_radix().Rollup merge of rust-lang#152267 - sorairolake:feature/nonzero-from-a…
Unrolled build for #152267
dimpolo commentedon Jun 24, 2026
nonzero_from_str_radixwas stabilized.Is it time to FCP this?
ajtribick commentedon Jul 20, 2026
Well I raised this one on Zulip and the discussion there suggested changing the API to:
So have raised #159554 to implement that.
Rollup merge of rust-lang#159554 - ajtribick:int_from_ascii_bytes, r=…
Rollup merge of rust-lang#159554 - ajtribick:int_from_ascii_bytes, r=…
Rollup merge of rust-lang#159554 - ajtribick:int_from_ascii_bytes, r=…
Unrolled build for #159554
Rollup merge of #159554 - ajtribick:int_from_ascii_bytes, r=Mark-Simu…
sorairolake commentedon Sep 3, 2026
If this feature is stabilized, I think it would be good to add a lint check for cases where
&stris passed as a parameter corresponding to these methods in Clippy.Could be written as:
ajtribick commentedon Sep 22, 2026
I don't know how much evidence is needed for the "experience" part of the stabilisation report, but I can verify that it works for the parser application I want to use it for. Minimal example: https://github.com/ajtribick/int_from_ascii_test
I would actually also need floating point versions of these functions ("float_from_ascii") but I don't think it makes sense to start work on those before stabilising this feature.