cargo thiserror 1.0.7

latest releases: 1.0.60, 1.0.59, 1.0.58...
4 years ago
  • Support mixing shorthand and non-shorthand format args (#47)

    #[derive(Error, Debug)]
    pub enum Error {
        #[error("first letter must be lowercase but was {:?}", first_char(.0))]
        WrongCase(String),
        #[error("invalid index {idx}, expected at least {} and at most {}", .limits.lo, .limits.hi)]
        OutOfBounds { idx: usize, limits: Limits },
    }
  • Add #[error(transparent)] attribute for delegating Error impl to one field (#50)

    This is useful for hiding error variants from a library's public error type:

    #[derive(Error, Debug)]
    #[error(transparent)]  // source and Display delegate to ErrorKind
    pub struct Error(ErrorKind);
    
    #[derive(Error, Debug)]
    /*private*/ enum ErrorKind {
        #[error("...")]
        E0,
        #[error("...")]
        E1(#[source] io::Error),
    }

    And also for enums that need an "anything else" variant; such variants tend not to have their own Display message but just forward through to the underlying error's Display and source:

    #[derive(Error, Debug)]
    pub enum MyError {
        ...
    
        #[error(transparent)]
        Other(#[from] anyhow::Error),  // source and Display delegate to anyhow::Error
    }

Don't miss a new thiserror release

NewReleases is sending notifications on new releases.