rust-lang / rust-lang/rfcs

make ParseIntError, ParseFloatError and ParseBoolError reusable (public)

Open
#1,143 5 comments 15 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

I'd like to reuse ParseIntError to write a wrapper for the as keyword to make sure the new value matches the old one. It could look like this:

fn convert_usize_to_isize(from: usize) -> Result<isize, ParseIntError> {
    let to = from as isize;
    match (to as usize) == from {
        true => Ok(to),
        false => Err(ParseIntError { kind: IntErrorKind::Overflow }),
    }
}

Furthermore, ParseIntError and ParseFloatError would be useful if one decides to create his own integer or float data type.

To make this work, ParseIntError's kind field, ParseFloatError's kind field and both enums IntErrorKind and FloatErrorKind have to be public.
Whether this should affect ParseBoolError should be discussed.

Contributor guide

No contributing guide indexed for this repository

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 proposed public API changes in the issue, including the error types, their kind fields, and the IntErrorKind and FloatErrorKind enums. Decide whether ParseBoolError belongs in the change, then define the public surface and confirm that the conversion example and custom numeric types can reuse these errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.