Skip to content

all Error types should be public? #39381

Closed
@getreu

Description

@getreu

In order to test the error behaviour of a function you need an error struct to compare with. For example:
since ParseIntError is private, I have to generate one by doing something wrong, like u8::from_str("257"). This leads to the following test:

let pie_overflow      = u8::from_str("257").unwrap_err();
assert_eq!(super::Missions::parse_enc_opt("ascii,256,U+41..U+67",8).unwrap_err(), pie_overflow );

If error types where public I would rather instantiate one and write:

let pie_overflow  = ParseIntError {kind: std::num::Overflow};
assert_eq!(super::Missions::parse_enc_opt("ascii,256,U+41..U+67",8).unwrap_err(), pie_overflow );

Maybe there is a reason I do not see why they are private and there is better more idiomatic way of doing error comparison?

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-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