Skip to content

Commit 0aa30d0

Browse files
raskydpc
authored andcommitted
Add a "nothreads" feature to drop Send+Sync requirements from OwnedKV.
When using slog in a single-threading context, the Send+Sync requirement means that we cannot use non-threadsafe objects as values or as part of a lazy value callback. This feature flag provides support for this scenario in a backward compatible way.
1 parent 1ad43e5 commit 0aa30d0

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ debug-assertions = false
2929
nested-values = ["erased-serde"]
3030
dynamic-keys = []
3131
std = []
32+
nothreads = []
3233
default = ["std"]
3334

3435
max_level_off = []

src/lib.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -3032,29 +3032,28 @@ where
30323032
}
30333033
}
30343034

3035-
#[cfg(feature = "std")]
3035+
#[cfg(feature = "nothreads")]
30363036
/// Thread-local safety bound for `KV`
30373037
///
30383038
/// This type is used to enforce `KV`s stored in `Logger`s are thread-safe.
3039+
pub trait SendSyncRefUnwindSafeKV: KV {}
3040+
3041+
#[cfg(feature = "nothreads")]
3042+
impl<T> SendSyncRefUnwindSafeKV for T where T: KV + ?Sized {}
3043+
3044+
#[cfg(all(not(feature = "nothreads"), feature = "std"))]
3045+
/// This type is used to enforce `KV`s stored in `Logger`s are thread-safe.
30393046
pub trait SendSyncRefUnwindSafeKV: KV + Send + Sync + RefUnwindSafe {}
30403047

3041-
#[cfg(feature = "std")]
3042-
impl<T> SendSyncRefUnwindSafeKV for T
3043-
where
3044-
T: KV + Send + Sync + RefUnwindSafe + ?Sized,
3045-
{
3046-
}
3048+
#[cfg(all(not(feature = "nothreads"), feature = "std"))]
3049+
impl<T> SendSyncRefUnwindSafeKV for T where T: KV + Send + Sync + RefUnwindSafe + ?Sized {}
30473050

3048-
#[cfg(not(feature = "std"))]
3051+
#[cfg(all(not(feature = "nothreads"), not(feature = "std")))]
30493052
/// This type is used to enforce `KV`s stored in `Logger`s are thread-safe.
30503053
pub trait SendSyncRefUnwindSafeKV: KV + Send + Sync {}
30513054

3052-
#[cfg(not(feature = "std"))]
3053-
impl<T> SendSyncRefUnwindSafeKV for T
3054-
where
3055-
T: KV + Send + Sync + ?Sized,
3056-
{
3057-
}
3055+
#[cfg(all(not(feature = "nothreads"), not(feature = "std")))]
3056+
impl<T> SendSyncRefUnwindSafeKV for T where T: KV + Send + Sync + ?Sized {}
30583057

30593058
/// Single pair `Key` and `Value`
30603059
pub struct SingleKV<V>(pub Key, pub V)

0 commit comments

Comments
 (0)