I've been using Snafu for many months and I get the idea that your error enum doesn't just impl From<OtherError> but converts from other errors by adding context.
However, sometimes I want there to be one effortless and general way to convert from one error (in my case ApiError) to another (the main Error), without adding any context.
Especially when the source error (ApiError) is just another snafu error enum that I made for my applicaiton. Say, for the sake of hierarchy. But also because one function I made, send_request(), returns Result<_, ApiError>
Actually, I would like to optionally attach context to the error returned from send_request(), so that sometimes I can call send_request()? and other times send_request().context(err::PollWorker)?. What I have now:
Then I will impl From<ApiError> for Error, which converts to Error::FromApiError I think.
No major problems here, but I wish there was some way, through attributes, that I could disable struct generation for the variant FromApiError, making From the only way to construct it (apart from manual construction).
I've been using Snafu for many months and I get the idea that your error enum doesn't just impl
From<OtherError>
but converts from other errors by adding context. However, sometimes I want there to be one effortless and general way to convert from one error (in my caseApiError
) to another (the mainError
), without adding any context. Especially when the source error (ApiError
) is just another snafu error enum that I made for my applicaiton. Say, for the sake of hierarchy. But also because one function I made,send_request()
, returnsResult<_, ApiError>
Actually, I would like to optionally attach context to the error returned fromsend_request()
, so that sometimes I can callsend_request()?
and other timessend_request().context(err::PollWorker)?
. What I have now:Then I will
impl From<ApiError> for Error
, which converts toError::FromApiError
I think. No major problems here, but I wish there was some way, through attributes, that I could disable struct generation for the variant FromApiError, making From the only way to construct it (apart from manual construction).