Skip to content

Tracking Issue for int_from_ascii #134821

Description

@niklasf

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(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>;
}
Upcoming with src: impl AsRef<[u8]>
// 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;
}

Steps / History

Unresolved Questions

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions