error-stack: Is there any way to clone error_stack::Result?
#2764
-
|
Both T and E implement Clone but I can't clone a Report. Is there any way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
|
No, a |
Beta Was this translation helpful? Give feedback.
-
|
@TimDiekmann hmm running into this now (caching a function output that returns a result), and I'm really torn on how to solve this. Do you have any ideas on what makes sense? Let's say for my project, I don't really care that errors don't impl clone, is there an easy fix? Like I wouldn't mind a version of .change_context that just wrapped anything not clone like std::io::Error into an Arc Or if I return an Arc is there an easy way to use the frames from that to reconstruct another report? |
Beta Was this translation helpful? Give feedback.
No, a
Reportcannot be cloned as the errors inside ofReportdon't necessarily implementClone. This would require a boundT: Cloneon any operation on Report (i.e. all contexts and attachments would need to beCloneable) but it's very common that errors don't implementClone. As a very prominent example,std::io::Errordoes not implementClone. Adding aClonebound would imply that many errors would not work witherror-stackanymore.