Skip to content

Commit a447574

Browse files
committed
Use serde_core instead of serde
Reduces compile times.
1 parent 60add84 commit a447574

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
This is noticeably faster than `std::sync::Mutex` in the uncontented case, is smaller, and avoids poisoning.
1515
* This feature has a separate name per version to allow supporting multiple versions of `parking_lot` at once. The current version (v0.12) has feature name `parking_lot_0_12`
1616
* Define a `prelude` module for common imports, allowing import of logging macros (`info!`, `!debug`, ...) and `slog::Logger` in one go.
17+
* Depend on [`serde_core`] rather than `serde` to reduce compile times.
1718

19+
[`serde_core`]: https://docs.rs/serde_core/1/serde_core/
1820
[`parking_lot::Mutex`]: https://docs.rs/parking_lot/latest/parking_lot/type.Mutex.html
1921

2022
### 2.8.0-rc.1 - 2025-08-06

Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,23 @@ default = ["std", "nested-values"]
5151
# usually requiring a nested-values feature flag on the logging backend.
5252
#
5353
# NOTE: Using nested-values requires Rust 1.56
54-
nested-values = ["erased-serde", "serde"]
54+
nested-values = ["dep:erased-serde", "dep:serde_core"]
5555
# DANGER: Use a String for slog::Key insated of &'static str
5656
#
5757
# This is discouraged, becauase it can break other libraries relying on slog.
5858
# If you really need to dynamically allocate keys, you can use String::leak to achieve the same functionality
5959
# without breaking other libraries.
6060
dynamic-keys = []
6161
# Require the standard library.
62-
std = ["serde?/std", "anyhow?/std"]
62+
std = ["serde_core?/std", "anyhow?/std"]
6363
# DANGER: Remove the Send + Sync bound from the default logger and drain.
6464
#
6565
# This feature is highly discouraged, because it could break other libraries relying on slog.
6666
# It is possible to achieve the same functionality by using a custom drain parameter to slog::Logger,
6767
# which will not break other libraries and avoids the overhead of an Arc.
6868
nothreads = []
6969

70-
# Implement serde::Value for anyhow::Error
70+
# Implement slog::Value for anyhow::Error
7171
anyhow = ["dep:anyhow"]
7272

7373
# Implement slog::Drain for parking_lot::Mutex.
@@ -105,7 +105,8 @@ release_max_level_debug = []
105105
release_max_level_trace = []
106106

107107
[dependencies]
108-
serde = { version = "1", optional = true, default-features = false }
108+
# Depending on serde_core rather than serde reduces compile times (added in serde v1.0.200)
109+
serde_core = { version = "1", optional = true, default-features = false }
109110
anyhow = { version = "1", optional = true, default-features = false }
110111
parking_lot_0_12 = { package = "parking_lot", version = "0.12", optional = true }
111112

@@ -125,6 +126,7 @@ rustversion = "1"
125126
# It is used to conditionally enable use of newer rust language
126127
# features depending on the compiler features.
127128
rustversion = "1"
129+
serde = "1"
128130
serde_derive = "1"
129131

130132
[[example]]

src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,7 +3035,7 @@ pub trait SerdeValue: erased_serde::Serialize + Value {
30353035
fn to_sendable(&self) -> Box<dyn SerdeValue + Send + 'static>;
30363036
}
30373037

3038-
/// Use to wrap a value that implements [serde::Serialize] so it's written to
3038+
/// Use to wrap a value that implements [serde::Serialize](serde_core::Serialize) so it's written to
30393039
/// the log record as an object, rather than a primitive.
30403040
///
30413041
/// # Examples
@@ -3063,25 +3063,25 @@ pub trait SerdeValue: erased_serde::Serialize + Value {
30633063
#[must_use = "must be passed to logger to actually log"]
30643064
pub struct Serde<T>(pub T)
30653065
where
3066-
T: serde::Serialize + Clone + Send + 'static;
3066+
T: serde_core::Serialize + Clone + Send + 'static;
30673067

30683068
#[cfg(feature = "nested-values")]
3069-
impl<T: serde::Serialize + Clone + Send + 'static> serde::Serialize
3069+
impl<T: serde_core::Serialize + Clone + Send + 'static> serde_core::Serialize
30703070
for Serde<T>
30713071
{
30723072
#[inline]
30733073
fn serialize<S>(&self, serializer: S) -> result::Result<S::Ok, S::Error>
30743074
where
3075-
S: serde::Serializer,
3075+
S: serde_core::Serializer,
30763076
{
3077-
serde::Serialize::serialize(&self.0, serializer)
3077+
serde_core::Serialize::serialize(&self.0, serializer)
30783078
}
30793079
}
30803080

30813081
#[cfg(feature = "nested-values")]
30823082
impl<T> SerdeValue for Serde<T>
30833083
where
3084-
T: serde::Serialize + Clone + Send + 'static,
3084+
T: serde_core::Serialize + Clone + Send + 'static,
30853085
{
30863086
fn as_serde(&self) -> &dyn erased_serde::Serialize {
30873087
&self.0
@@ -3703,7 +3703,7 @@ where
37033703
#[cfg(feature = "nested-values")]
37043704
impl<T> Value for Serde<T>
37053705
where
3706-
T: serde::Serialize + Clone + Send + 'static,
3706+
T: serde_core::Serialize + Clone + Send + 'static,
37073707
{
37083708
fn serialize(
37093709
&self,

0 commit comments

Comments
 (0)