5 releases

0.2.3 Nov 22, 2024
0.2.2 Nov 15, 2024
0.2.1 Nov 15, 2024
0.2.0 Nov 15, 2024
0.1.0 Nov 14, 2024

#203 in Procedural macros

Download history 312/week @ 2024-11-14 1372/week @ 2024-11-21 1253/week @ 2024-11-28 1726/week @ 2024-12-05 1912/week @ 2024-12-12 1775/week @ 2024-12-19 1516/week @ 2024-12-26 1608/week @ 2025-01-02

7,104 downloads per month
Used in 19 crates (13 directly)

MIT license

8KB
141 lines

boxed_error

Experimental opinionated way to provide helper methods for use with boxing errors.

Before:

use thiserror::Error;

#[derive(Error, Debug)]
#[error(transparent)]
pub struct DenoResolveError(pub Box<DenoResolveErrorKind>);

impl DenoResolveError {
  pub fn as_kind(&self) -> &DenoResolveErrorKind {
    &self.0
  }

  pub fn into_kind(self) -> DenoResolveErrorKind {
    *self.0
  }
}

impl<E> From<E> for DenoResolveError
where
  DenoResolveErrorKind: From<E>,
{
  fn from(err: E) -> Self {
    DenoResolveError(Box::new(DenoResolveErrorKind::from(err)))
  }
}

#[derive(Debug, Error)]
pub enum DenoResolveErrorKind {
  #[error("Importing ...")]
  InvalidVendorFolderImport,
  #[error(transparent)]
  MappedResolution(#[from] MappedResolutionError),
  // ...
}

impl DenoResolveErrorKind {
  pub fn into_box(self) -> DenoResolveError {
    DenoResolveError(Box::new(self))
  }
}

After:

use boxed_error::Boxed;
use thiserror::Error;

#[derive(Debug, Boxed)]
pub enum DenoResolveError(pub Box<DenoResolveErrorKind>);

#[derive(Debug, Error)]
pub enum DenoResolveErrorKind {
  #[error("Importing ...")]
  InvalidVendorFolderImport,
  #[error(transparent)]
  MappedResolution(#[from] MappedResolutionError),
  // ...
}

Dependencies

~245–700KB
~17K SLoC