rust-lang / rust-lang/rust

Tracking Issue for `int_from_ascii`

Open
#134,821 19 comments 26 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-tracking-issue T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

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: #105206
  • API change proposal: https://github.com/rust-lang/libs-team/issues/469
  • Implementation for T: #134824
  • Implementation for NonZero<T>: #152267
  • from_ascii -> from_ascii_bytes and src: &[u8] -> src: impl AsRef<[u8]>: #159554
  • Final comment period (FCP)^1
  • Stabilization PR
Unresolved Questions
  • Stabilize #152193 first

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the API change proposal in libs-team issue #469, the implementation PRs #134824, #152267, and #159554, and the stabilization guide linked in the FCP checklist. Done means completing the final comment period and landing a stabilization PR for the documented integer and NonZero APIs.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.