dtolnay / thiserror

derive(Error) for struct and enum error types

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Transparent boxed from types

devyn opened this issue · comments

It's not ideal for an error type to take up a lot of memory on its own, but if you're including external libraries' error types into yours with #[from], this could easily happen, as an enum is always at least as large as its largest variant. A function that only needs to return an i32 in its happy path might potentially be weighed down by a behemoth of an error type with many fields on the order of a hundred or more bytes.

Ideally I think if an #[error] variant has a #[from] field that's a Box<T>, the From implementation should transparently be for T and not for the Box. That might break someone's code at this point though, so it's probably better to add something like #[from(boxed)]

Previous discussion: #57

I would prefer not to build this into thiserror, but our From support is all opt-in and optional so it should be possible to use a different derive macro for all your From impls.