Some recent clippy update warns for large enum error variants, and recommends boxing them. This is probably reasonable. It would be convenient if there was an annotation like from which would create the box itself rather than having to manually implement an increasingly common use case.
Looks like thiserror_ext has a related utility already: https://docs.rs/thiserror-ext/latest/thiserror_ext/derive.Box.html but could probably be cleaner. Something like
use thiserror::Error;
#[derive(Error, Debug)]
pub enum MyError {
Small(#[from] small::Error),
Big(#[from(autobox)] Box<big::Error>)
}
which would generate something like
use thiserror::Error;
#[derive(Error, Debug)]
pub enum MyError {
Small(small::Error),
Big(Box<big::Error>)
}
impl From<small::Error> for MyError {
fn from(value: small::Error) -> Self {
Self::Small(value)
}
}
impl From<big::Error> for MyError {
fn from(value: big::Error) -> Self {
Self::Big(Box::new(value))
}
}
Maybe with an impl From<Box<big::Error>> for MyError too, for completeness.
Some recent clippy update warns for large enum error variants, and recommends boxing them. This is probably reasonable. It would be convenient if there was an annotation like
fromwhich would create the box itself rather than having to manually implement an increasingly common use case.Looks like
thiserror_exthas a related utility already: https://docs.rs/thiserror-ext/latest/thiserror_ext/derive.Box.html but could probably be cleaner. Something likewhich would generate something like
Maybe with an
impl From<Box<big::Error>> for MyErrortoo, for completeness.