cargo thiserror 1.0.29

latest releases: 1.0.59, 1.0.58, 1.0.57...
2 years ago
  • Support error types containing generic type parameters (#148, #149, #150, #151)

    use thiserror::Error;
    
    #[derive(Error, Debug)]
    pub enum MyError<E, F, G> {
        #[error("thing {0} ({0:?})")]
        Variant(E),
        #[error("some error")]
        Delegate(#[source] SomeError<F>),
        #[error("err 0o{val:o}")]
        Octal { val: G },
    }

    In the above example, thiserror would automatically generate the following pair of generic trait impls.

    impl<E, F, G> std::error::Error for MyError<E, F, G>
    where
        SomeError<F>: std::error::Error + 'static,
        Self: std::fmt::Debug + std::fmt::Display;
    
    impl<E, F, G> std::fmt::Display for MyError<E, F, G>
    where
        E: std::fmt::Debug + std::fmt::Display,
        G: std::fmt::Octal;

Don't miss a new thiserror release

NewReleases is sending notifications on new releases.