-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why isn't Whatever Send + Sync by default? #446
Comments
I managed to get snafu's Snafu compiles and tests run on my machine with this. From my naive testing in one of my personal projects, it successfully allows for I am curious to hear your thoughts. Thanks! |
I'm not an expert in send and sync trait I often try to avoid them :p but I think sync is not needed here it's maybe too much requirement, I don't see a case where you would need to share a reference to a I think the error here is solved with just send that is a perfectly reasonable constraint for a |
It is unclear whether the lack of In any case, making the change now is a breaking change, so I will mark it as such in the pull request. |
Ah, that is true. The error I experienced was only in relation to
Great point @Enet4. Would making the error type only
Would there be a better method to allow users to enable |
Just chiming in to say that there are use cases where |
Hi @shepmaster! Thank you for the wonderful crate!
Problem
I have been switching my project to utilize
snafu
. Previously, I usedanyhow::Error
as a generic error type when I didn't understand how to implement error types. Now I am rewriting my project with proper error types, and in the meantime switching outanyhow::Error
withsnafu::Whatever
.When switching, I ran into a problem. I have a future being spawned via Tokio, where the future has a output type of
Result<(), snafu::Whatever>
. As this is concurrency, the rust compiler complains that thatWhatever
does not haveSend + Sync
markers for its source type. The compile error is pretty indirect about this issue. I have the error included at the bottom of this post. To figure out where this issue was coming from required a bunch of research, as shown below.Research
Searching "snafu thread saftey" on Google returns the project
http-whatever
, where they essentially implement a new Whatever but withSend + Sync
attached to theStdError
:https://github.com/bassmanitram/http-whatever/blob/af4fb2d672011e76a5746c27f31a2fdf65979326/src/lib.rs#L84-L93
Snafu's Whatever:
snafu/src/lib.rs
Lines 1557 to 1569 in 073cc38
I found a snafu issue from January 2022 that asks for implementation details for making a custom snafu error type be async compatible. From there in May 2022 a PR was merged that showed an error type with async/multi-threading as part of the tests. This is part of the tests, but not part of the examples, so finding this example required a bunch of searching as its not part of the doc examples.
In addition,
anyhow::Error
hasSync + Send
markers (source in anyhow code, source in anyhow docs).Question
Why isn't
Whatever
Send + Sync by default?I could implement a new Whatever as done by
http-whatever
and as shown in the snafu test. But, if we considersnafu::Whatever
to be a catch-all error type until the user can make more specific types, shouldn't we expect as a user that it can be used in all places including async and multi-threading? Is there a detail I am missing that makes Whatever not able to be Send + Sync compatible by default?Thank you!
Whatever Send + Sync error report
The text was updated successfully, but these errors were encountered: