Make Whatever thread-safe by default (add markers `Send + Sync`)
Allows Whatever's to be sent between threads by making them thread-safe by marking the source std::error::Error with Send + Sync.
For more discussion on why, see issue #446.
Resolves #446.
Deploy Preview for shepmaster-snafu ready!
| Name | Link |
|---|---|
| Latest commit | 0d7792e5c282ab0c117a09ebd1a750f1d972e188 |
| Latest deploy log | https://app.netlify.com/sites/shepmaster-snafu/deploys/660c73e8382fe40008b5f9e0 |
| Deploy Preview | https://deploy-preview-448--shepmaster-snafu.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
News?
Well, since my comment on https://github.com/shepmaster/snafu/issues/446#issuecomment-2033809122, no one has expressed concern over this change, but this also doesn't mean that someone out there is depending on Whatever not having to be Send or Sync.
At some point I hope we can move forward with this, since it does seem desirable and makes the error type more usable. It will imply a semver bump in any case.
Still think sync is not needed
So can you share the best practices when using snafu in async Rust? Thanks!
Is it recommended to use Whatever in an async context or multi-threaded environment?
would an additional WhateverAsync be possible so no semver bump would be needed?
an additional WhateverAsync be possible
Yep! You can do this today by copy-pasting the Whatever type into your code and modifying it. Stealing from this PR:
// You pick if you want `+ Send`, `+ Sync`, both, or neither! Change it in all 3 places.
#[derive(Debug, Snafu)]
#[snafu(whatever)]
#[snafu(display("{message}"))]
#[snafu(provide(opt, ref, chain, dyn std::error::Error + Send + Sync => source.as_deref()))]
pub struct WhateverAsync {
#[snafu(source(from(Box<dyn std::error::Error + Send + Sync>, Some)))]
#[snafu(provide(false))]
source: Option<Box<dyn std::error::Error + Send + Sync>>,
message: String,
backtrace: Backtrace,
}