Would it be so bad if you could opt into #[from]
generating From<..> for Box<..>
?
#418
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @dtolnay! Long time listener, first time caller. Please, step into my bikeshed.
I'm looking to change your mind about #57, #302 and #415. I think I understand your position, and I'd like to share mine. I thought that actually bothering to take a crack at it would give me an idea of how burdensome this feature would be to
thiserror
's users and maintainer.Anyhow (hah!), I've put together a crude first pass of a new opt-in feature called
autobox
, that, well, automatically boxesthiserror
-derived (enum only for now) errors, as shown in the new test code:I am sure that you have opinions on the implementation details, but I'm here to argue for this feature being desirable in
thiserror
, even though you've said you don't want it.Firstly, like the existing
#[from]
implementations, the new feature and derived code is entirely opt in. Indeed, the new code is masked out by a feature flag, so the proc macro does nothing new unless you explicitly ask it to. As such, the newimpl
s won't ever conflict with existing into-box implementations, whether hand-written or derived by another macro.Secondly, I'd argue that now that Clippy's
result_large_err
is stabilized, more and more people are going to bump into this lint, and therefore there is some "public interest" in the existence of an easy solution that isn't hand-writing the from-for-box impl. Other proc macro crates could certainly achieve the same thing, yes. But, no existing crate, not evenderive_more
, is as convenient or widely trusted asthiserror
. I don't want to take a dependency on yet another crate for a fairly trivial impl.Finally, I'd like to say that this new feature doesn't actually require non-trivial changes to
thiserror
s internals, so far as I can tell.As an aside, I'd like to disarm the anti-Rust crowd who in the future will inevitably wheel out the "look at all those needless
memcpy
s" strawman.