rust-ux / uX

Non standard integer types like `u7`, `u9`, `u10`, `u63`, `i7`, `i9`
Apache License 2.0
119 stars 37 forks source link

Implement std::error::Error for TryFromIntError #61

Closed barometz closed 10 months ago

barometz commented 11 months ago

.. which unfortunately requires std until error_in_core (rust-lang/rust#103765) is stabilized, so the std feature is no longer a no-op. If that means you'd prefer to wait for error_in_core, that's fine with me.

The net result here is that TryFromIntError plays nice with crates such as anyhow, and the following compiles:

#[cfg(feature = "std")]
mod test_anyhow {
    use anyhow::Result;
    use super::*;
    fn testing_anyhow() -> Result<u6> {
        Ok(u6::try_from(u63::new(63))?)
    }
}

The error description is copied verbatim from its std::num counterpart: https://doc.rust-lang.org/src/core/num/error.rs.html#24

bbaldino commented 11 months ago

To me this seems like it'd be nice, and given that there's already an std feature it seems reasonable to just use it as a gate for this. Will give a bit longer to see if anyone else has any thoughts.