From 15af08e664acdaef09009d6f7175e0aab2437939 Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 3 Dec 2026 07:59:37 +0800 Subject: [PATCH 1/2] refactor(core): replace ValueSerde::try_into_owned with ValueSerde::try_serialize `ValueSerde::try_into_owned(self)` bypassed any cached snapshot on the adapter instance, allowing `into_owned()` and `try_into_owned()` on an already-inspected adapter to observe different values under interior mutability while requiring callers who only want fallible serialization to construct a throwaway `ValueSerde`. Replace `ValueSerde::try_into_owned(self)` with the associated function `ValueSerde::try_serialize(value: &'a T) -> Result` so each `ValueSerde` instance strictly represents a single memoized lazy snapshot. Signed-off-by: tison --- CHANGELOG.md | 2 +- core/src/kv/value_serde.rs | 23 +++++++++++++--------- tests-integration/tests/bridge_test/log.rs | 2 +- tests-integration/tests/core_test/kv.rs | 16 ++++++--------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33b87087..1aa7bac2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,7 +67,7 @@ All significant changes to this project will be documented in this file. * Add native structured logging macros (`log!`, `trace!`, `debug!`, `info!`, `warn!`, `error!`, and `fatal!`) in `logforth-core` and `logforth` supporting bracketed `"key" = value` fields on explicit `Logger` handles. * Add `Level::ALL` and `RecordBuilder::time` in `logforth-core` to enumerate all 24 severities and construct records with an explicit observed timestamp. -* Add `kv::ValueSerde` (`new`, `into_owned`, `try_into_owned`, `Deref`, `LogValue`, and `From>` for `ValueOwned`, behind the `serde` feature) in `logforth-core` to capture `serde::Serialize` values as lazy structured fields or materialize them into `ValueOwned` snapshots without panicking. +* Add `kv::ValueSerde` (`new`, `into_owned`, `try_serialize`, `Deref`, `LogValue`, and `From>` for `ValueOwned`, behind the `serde` feature) in `logforth-core` to capture `serde::Serialize` values as lazy structured fields or materialize them into `ValueOwned` snapshots without panicking. * Add `kv::LogValue`, `Value::{owned, lazy_owned, to_owned}`, `Key::{as_str, to_owned}`, `KeyOwned::as_str`, `DebugValue::new`, `DisplayValue::new`, `KeyView::to_static_str`, and `ValueView::{is_none, to_bytes}` in `logforth-core`, and implement `From` on `kv::{KeyOwned, ValueOwned}` across scalars (including `NonZero*` integers), strings, byte slices, `Option`, and borrowed `kv::{Key, KeyView, Value, ValueView}`. * Add `ThreadLocalDiagnostic::scope` and `ThreadLocalDiagnosticGuard` in `logforth-core` for `!Send` RAII scoped thread-local diagnostics that restore shadowed entries on drop. * Add `Error::message` and `LoggerBuilder::error_sink` in `logforth-core` (plus `starter_log::LogStarter::error_sink` in `logforth`) to inspect an error's own message and configure runtime error handling. diff --git a/core/src/kv/value_serde.rs b/core/src/kv/value_serde.rs index 141c20b1..5681d8f5 100644 --- a/core/src/kv/value_serde.rs +++ b/core/src/kv/value_serde.rs @@ -65,23 +65,28 @@ impl<'a, T: serde::Serialize + ?Sized> ValueSerde<'a, T> { .unwrap_or_else(|| Self::serialize(self.value)) } - /// Consumes the adapter and serializes the borrowed value even if a snapshot is cached. + /// Immediately serializes the borrowed value into a [`ValueOwned`] snapshot. /// /// # Errors /// - /// Returns the error from this serialization attempt. - pub fn try_into_owned(self) -> Result { - Self::try_serialize(self.value) + /// Returns an error if the value fails to serialize. + /// + /// # Examples + /// + /// ``` + /// use logforth_core::kv::ValueSerde; + /// + /// let snapshot = ValueSerde::try_serialize("ready").unwrap(); + /// assert_eq!(snapshot.view().to_str(), Some("ready")); + /// ``` + pub fn try_serialize(value: &'a T) -> Result { + value.serialize(ValueSerializer).map_err(|err| err.0) } - fn serialize(value: &T) -> ValueOwned { + fn serialize(value: &'a T) -> ValueOwned { Self::try_serialize(value) .unwrap_or_else(|err| ValueOwned::str(format!("", err.message()))) } - - fn try_serialize(value: &T) -> Result { - value.serialize(ValueSerializer).map_err(|err| err.0) - } } impl Deref for ValueSerde<'_, T> { diff --git a/tests-integration/tests/bridge_test/log.rs b/tests-integration/tests/bridge_test/log.rs index eddb4a1e..c12deef7 100644 --- a/tests-integration/tests/bridge_test/log.rs +++ b/tests-integration/tests/bridge_test/log.rs @@ -302,7 +302,7 @@ fn fallible_kv_source_and_failing_display_never_panic() { assert_eq!(fields.get("first").unwrap().to_u64(), Some(7)); }); - assert!(ValueSerde::new(&FailingDisplay).try_into_owned().is_err()); + assert!(ValueSerde::try_serialize(&FailingDisplay).is_err()); let fallback = ValueSerde::new(&FailingDisplay).into_owned(); bridge.log( &log::Record::builder() diff --git a/tests-integration/tests/core_test/kv.rs b/tests-integration/tests/core_test/kv.rs index 65946ab4..62f1b8c9 100644 --- a/tests-integration/tests/core_test/kv.rs +++ b/tests-integration/tests/core_test/kv.rs @@ -470,7 +470,7 @@ fn serde_captures_structured_trees_and_degrades_gracefully_on_failure() { numeric_map: BTreeMap::from([(200, "ok")]), }; - let owned = ValueSerde::new(&payload).try_into_owned().unwrap(); + let owned = ValueSerde::try_serialize(&payload).unwrap(); let root = owned.view().to_map().unwrap(); assert!(matches!(root.get("unit").unwrap(), ValueView::None)); @@ -528,7 +528,7 @@ fn serde_captures_structured_trees_and_degrades_gracefully_on_failure() { assert_eq!(numeric_map.get("200").unwrap().to_str(), Some("ok")); // Round-trip `ValueOwned`, `KeyValues`, `DebugValue`, and `DisplayValue` through `Serialize`. - let reserialized = ValueSerde::new(&owned).try_into_owned().unwrap(); + let reserialized = ValueSerde::try_serialize(&owned).unwrap(); assert_eq!( reserialized .view() @@ -543,15 +543,13 @@ fn serde_captures_structured_trees_and_degrades_gracefully_on_failure() { (Key::new("dbg"), Value::debug(&42_u32)), (Key::new("disp"), Value::display(&"plain")), ]; - let serialized_kvs = ValueSerde::new(&KeyValues::from(fmt_entries.as_slice())) - .try_into_owned() - .unwrap(); + let serialized_kvs = + ValueSerde::try_serialize(&KeyValues::from(fmt_entries.as_slice())).unwrap(); let kvs_map = serialized_kvs.view().to_map().unwrap(); assert_eq!(kvs_map.get("dbg").unwrap().to_str(), Some("42")); assert_eq!(kvs_map.get("disp").unwrap().to_str(), Some("plain")); assert_eq!( - ValueSerde::new(&DebugValue::new(&7_u8)) - .try_into_owned() + ValueSerde::try_serialize(&DebugValue::new(&7_u8)) .unwrap() .view() .to_str(), @@ -565,9 +563,7 @@ fn serde_captures_structured_trees_and_degrades_gracefully_on_failure() { ); // Fallible `Serialize` implementations return `Err` or a non-panicking placeholder string. - let err = ValueSerde::new(&FallibleSerialize) - .try_into_owned() - .unwrap_err(); + let err = ValueSerde::try_serialize(&FallibleSerialize).unwrap_err(); assert_eq!(err.message(), "cannot serialize secret"); let fallback = ValueSerde::new(&FallibleSerialize).into_owned(); assert_eq!( From b7172dc1a7e32645bdb3e27971af9bc2d6f3a5d4 Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 3 Dec 2026 08:17:28 +0800 Subject: [PATCH 2/2] refactor(core): restore ValueOwned serde constructors and keep ValueSerde lazy-only Restore `ValueOwned::from_serde` and `ValueOwned::try_from_serde` for eager owned conversion, and narrow `kv::ValueSerde` to a pure lazy-initialization field wrapper (`new`, `Deref`, `LogValue`, and `Debug`) without eager conversion methods. Signed-off-by: tison --- CHANGELOG.md | 2 +- README.md | 49 +++++++------- bridges/log/src/lib.rs | 4 +- core/README.md | 2 +- core/src/kv/mod.rs | 6 +- core/src/kv/value_serde.rs | 75 ++++++++++------------ logforth/src/lib.rs | 2 +- tests-integration/tests/bridge_test/log.rs | 5 +- tests-integration/tests/core_test/kv.rs | 15 ++--- 9 files changed, 75 insertions(+), 85 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aa7bac2..37d4a31e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,7 +67,7 @@ All significant changes to this project will be documented in this file. * Add native structured logging macros (`log!`, `trace!`, `debug!`, `info!`, `warn!`, `error!`, and `fatal!`) in `logforth-core` and `logforth` supporting bracketed `"key" = value` fields on explicit `Logger` handles. * Add `Level::ALL` and `RecordBuilder::time` in `logforth-core` to enumerate all 24 severities and construct records with an explicit observed timestamp. -* Add `kv::ValueSerde` (`new`, `into_owned`, `try_serialize`, `Deref`, `LogValue`, and `From>` for `ValueOwned`, behind the `serde` feature) in `logforth-core` to capture `serde::Serialize` values as lazy structured fields or materialize them into `ValueOwned` snapshots without panicking. +* Add `ValueOwned::{from_serde, try_from_serde}` and `kv::ValueSerde` (`new`, `Deref`, and `LogValue`, behind the `serde` feature) in `logforth-core` to convert `serde::Serialize` values into `ValueOwned` snapshots without panicking or capture them as lazy structured fields. * Add `kv::LogValue`, `Value::{owned, lazy_owned, to_owned}`, `Key::{as_str, to_owned}`, `KeyOwned::as_str`, `DebugValue::new`, `DisplayValue::new`, `KeyView::to_static_str`, and `ValueView::{is_none, to_bytes}` in `logforth-core`, and implement `From` on `kv::{KeyOwned, ValueOwned}` across scalars (including `NonZero*` integers), strings, byte slices, `Option`, and borrowed `kv::{Key, KeyView, Value, ValueView}`. * Add `ThreadLocalDiagnostic::scope` and `ThreadLocalDiagnosticGuard` in `logforth-core` for `!Send` RAII scoped thread-local diagnostics that restore shadowed entries on drop. * Add `Error::message` and `LoggerBuilder::error_sink` in `logforth-core` (plus `starter_log::LogStarter::error_sink` in `logforth`) to inspect an error's own message and configure runtime error handling. diff --git a/README.md b/README.md index c6f300d0..6de12db5 100644 --- a/README.md +++ b/README.md @@ -146,35 +146,36 @@ Runnable end-to-end scenarios live in the [`examples`](examples) workspace crate `logforth` enables no optional features by default. Enable only the components your application uses: -| Category | APIs | Feature | Use | -| :---------- | :---------------------------------------- | :------------------------------- | :------------------------------------------------------------------------------- | -| Core APIs | [`Logger`], [`Record`], [`kv`], [`info!`] | *built-in* | Build loggers and emit structured records with key-value fields. | -| | [`ValueSerde`] | `serde` | Convert `serde::Serialize` values into [`kv`] fields and serialize [`kv`] types. | -| Appenders | [`Stdout`], [`Stderr`], [`Testing`] | *built-in* | Write formatted lines to standard output, standard error, or test output. | -| | [`File`] | `append-file` | Write to a single file or time- and size-rotated log files. | -| | [`Async`] | `append-async` | Offload downstream appender I/O onto a background worker thread. | -| | [`Journald`] | `append-journald` | Send structured log entries directly to `systemd-journald` on Unix. | -| | [`SocketSyslog`], [`PosixSyslog`] | `append-syslog` | Send logs to local or remote syslog daemons. | -| | [`OpentelemetryLog`] | `append-opentelemetry` | Export structured OpenTelemetry log batches with trace correlation. | -| | [`FastraceEvent`] | `append-fastrace` | Attach log records as events on active [`fastrace`] spans. | -| Layouts | [`PlainTextLayout`] | *built-in* | Minimal uncolored single-line text output. | -| | [`TextLayout`] | `layout-text` | Human-readable single-line text with timestamps and ANSI colors. | -| | [`LogfmtLayout`] | `layout-logfmt` | Single-line `key=value` [`logfmt`] output. | -| | [`JsonLayout`] | `layout-json` | Single-line JSON output. | -| | [`GoogleCloudLoggingLayout`] | `layout-google-cloud-logging` | Structured JSON output for Google Cloud Logging. | -| Filters | [`LevelFilter`] | *built-in* | Filter records by severity threshold. | -| | [`RustLogFilter`] | `filter-rustlog` | Filter by module or target prefix using `RUST_LOG` directives. | -| Diagnostics | [`StaticDiagnostic`] | *built-in* | Attach process-wide key-value fields such as service name or version. | -| | [`ThreadLocalDiagnostic`] | *built-in* | Attach scoped key-value fields on the current thread. | -| | [`TaskLocalDiagnostic`] | `diagnostic-task-local` | Attach scoped key-value fields to an async `Future`. | -| | [`FastraceDiagnostic`] | `diagnostic-fastrace` | Attach trace and span IDs from active [`fastrace`] spans. | -| Bridges | [`starter_log`] | `starter-log` | Quick-start presets for installing Logforth as the global [`log`] backend. | -| | [`LogBridge`] | `bridge-log`, `bridge-log-serde` | Forward [`log`] records and `log::kv` fields into a `Logger`. | +| Category | APIs | Feature | Use | +| :---------- | :----------------------------------------- | :------------------------------- | :------------------------------------------------------------------------------- | +| Core APIs | [`Logger`], [`Record`], [`kv`], [`info!`] | *built-in* | Build loggers and emit structured records with key-value fields. | +| | [`ValueOwned::from_serde`], [`ValueSerde`] | `serde` | Convert `serde::Serialize` values into [`kv`] fields and serialize [`kv`] types. | +| Appenders | [`Stdout`], [`Stderr`], [`Testing`] | *built-in* | Write formatted lines to standard output, standard error, or test output. | +| | [`File`] | `append-file` | Write to a single file or time- and size-rotated log files. | +| | [`Async`] | `append-async` | Offload downstream appender I/O onto a background worker thread. | +| | [`Journald`] | `append-journald` | Send structured log entries directly to `systemd-journald` on Unix. | +| | [`SocketSyslog`], [`PosixSyslog`] | `append-syslog` | Send logs to local or remote syslog daemons. | +| | [`OpentelemetryLog`] | `append-opentelemetry` | Export structured OpenTelemetry log batches with trace correlation. | +| | [`FastraceEvent`] | `append-fastrace` | Attach log records as events on active [`fastrace`] spans. | +| Layouts | [`PlainTextLayout`] | *built-in* | Minimal uncolored single-line text output. | +| | [`TextLayout`] | `layout-text` | Human-readable single-line text with timestamps and ANSI colors. | +| | [`LogfmtLayout`] | `layout-logfmt` | Single-line `key=value` [`logfmt`] output. | +| | [`JsonLayout`] | `layout-json` | Single-line JSON output. | +| | [`GoogleCloudLoggingLayout`] | `layout-google-cloud-logging` | Structured JSON output for Google Cloud Logging. | +| Filters | [`LevelFilter`] | *built-in* | Filter records by severity threshold. | +| | [`RustLogFilter`] | `filter-rustlog` | Filter by module or target prefix using `RUST_LOG` directives. | +| Diagnostics | [`StaticDiagnostic`] | *built-in* | Attach process-wide key-value fields such as service name or version. | +| | [`ThreadLocalDiagnostic`] | *built-in* | Attach scoped key-value fields on the current thread. | +| | [`TaskLocalDiagnostic`] | `diagnostic-task-local` | Attach scoped key-value fields to an async `Future`. | +| | [`FastraceDiagnostic`] | `diagnostic-fastrace` | Attach trace and span IDs from active [`fastrace`] spans. | +| Bridges | [`starter_log`] | `starter-log` | Quick-start presets for installing Logforth as the global [`log`] backend. | +| | [`LogBridge`] | `bridge-log`, `bridge-log-serde` | Forward [`log`] records and `log::kv` fields into a `Logger`. | [`Logger`]: https://docs.rs/logforth/0.31.0/logforth/struct.Logger.html [`Record`]: https://docs.rs/logforth/0.31.0/logforth/record/struct.Record.html [`kv`]: https://docs.rs/logforth/0.31.0/logforth/kv/index.html [`info!`]: https://docs.rs/logforth/0.31.0/logforth/macro.info.html +[`ValueOwned::from_serde`]: https://docs.rs/logforth/0.31.0/logforth/kv/struct.ValueOwned.html#method.from_serde [`ValueSerde`]: https://docs.rs/logforth/0.31.0/logforth/kv/struct.ValueSerde.html [`Stdout`]: https://docs.rs/logforth/0.31.0/logforth/append/struct.Stdout.html [`Stderr`]: https://docs.rs/logforth/0.31.0/logforth/append/struct.Stderr.html diff --git a/bridges/log/src/lib.rs b/bridges/log/src/lib.rs index da69701d..2e6f4400 100644 --- a/bridges/log/src/lib.rs +++ b/bridges/log/src/lib.rs @@ -243,8 +243,6 @@ mod kv { use logforth_core::kv::Key; use logforth_core::kv::Value; use logforth_core::kv::ValueOwned; - #[cfg(feature = "serde")] - use logforth_core::kv::ValueSerde; use crate::KEY_LOG_TARGET; @@ -311,7 +309,7 @@ mod kv { impl<'a> log::kv::VisitValue<'a> for ValueVisitor<'a> { fn visit_any(&mut self, value: log::kv::Value) -> Result<(), log::kv::Error> { #[cfg(feature = "serde")] - let owned = ValueSerde::new(&value).into_owned(); + let owned = ValueOwned::from_serde(&value); #[cfg(not(feature = "serde"))] let owned = { let mut buf = String::new(); diff --git a/core/README.md b/core/README.md index 7f09eb9f..013ac73a 100644 --- a/core/README.md +++ b/core/README.md @@ -79,7 +79,7 @@ fn build_json_logger() -> Result { `logforth-core` enables no features by default: -- `serde`: adds `kv::ValueSerde` to capture `serde::Serialize` values as lazy structured fields or `ValueOwned` snapshots, and implements `serde::Serialize` across `kv` types. +- `serde`: adds `ValueOwned::from_serde`, `ValueOwned::try_from_serde`, and `kv::ValueSerde` to capture `serde::Serialize` values as `ValueOwned` snapshots or lazy structured fields, and implements `serde::Serialize` across `kv` types. ## Documentation diff --git a/core/src/kv/mod.rs b/core/src/kv/mod.rs index 38e4589c..8426a7fd 100644 --- a/core/src/kv/mod.rs +++ b/core/src/kv/mod.rs @@ -23,9 +23,9 @@ //! - **Owned snapshots** ([`KeyOwned`], [`ValueOwned`]) carry `'static + Send + Sync` structured //! trees across thread boundaries and diagnostic scopes. //! -//! With the `serde` feature enabled, `ValueSerde` adapts `serde::Serialize` values into lazy -//! borrowed [`Value`] fields or [`ValueOwned`] snapshots, and key-value carriers and views -//! implement `serde::Serialize`. +//! With the `serde` feature enabled, [`ValueOwned::from_serde`] and [`ValueOwned::try_from_serde`] +//! eagerly capture [`ValueOwned`] snapshots, while [`ValueSerde`] initializes structured fields +//! lazily. Key-value carriers and views implement `serde::Serialize`. //! //! Iteration over [`KeyValues`] and [`MapValue`] preserves insertion order, while point lookups via //! [`KeyValues::get`] and [`MapValue::get`] resolve duplicate keys using last-entry-wins order. diff --git a/core/src/kv/value_serde.rs b/core/src/kv/value_serde.rs index 5681d8f5..8e94cee4 100644 --- a/core/src/kv/value_serde.rs +++ b/core/src/kv/value_serde.rs @@ -24,12 +24,42 @@ use crate::kv::Value; use crate::kv::ValueOwned; use crate::kv::ValueOwnedState; +impl ValueOwned { + /// Immediately serializes the borrowed value into an owned snapshot. + /// + /// A serialization failure returns the string `""` instead of + /// panicking. + pub fn from_serde(value: &(impl serde::Serialize + ?Sized)) -> Self { + Self::try_from_serde(value) + .unwrap_or_else(|err| Self::str(format!("", err.message()))) + } + + /// Immediately serializes the borrowed value into a [`ValueOwned`] snapshot. + /// + /// # Errors + /// + /// Returns an error if the value fails to serialize. + /// + /// # Examples + /// + /// ``` + /// use logforth_core::kv::ValueOwned; + /// + /// let snapshot = ValueOwned::try_from_serde("ready").unwrap(); + /// assert_eq!(snapshot.view().to_str(), Some("ready")); + /// ``` + pub fn try_from_serde(value: &(impl serde::Serialize + ?Sized)) -> Result { + value.serialize(ValueSerializer).map_err(|err| err.0) + } +} + /// A borrowed [`serde::Serialize`] value for lazy structured logging. /// /// The first dereference serializes the value and caches the [`ValueOwned`] snapshot. /// If serialization fails, the snapshot contains the string `""`. /// When `T: Sync`, [`LogValue`] lets dispatches share this snapshot and defers -/// serialization until a dispatch inspects the field. +/// serialization until a dispatch inspects the field. For an eager snapshot, use +/// [`ValueOwned::from_serde`] or [`ValueOwned::try_from_serde`]. /// /// # Examples /// @@ -40,7 +70,7 @@ use crate::kv::ValueOwnedState; /// let field = ValueSerde::new(&[2, 3]); /// let list = field.log_value().view().to_list().unwrap(); /// assert_eq!(list.iter().next().unwrap().to_i64(), Some(2)); -/// assert_eq!(field.into_owned().view().to_list().unwrap().len(), 2); +/// assert_eq!(field.view().to_list().unwrap().len(), 2); /// ``` pub struct ValueSerde<'a, T: serde::Serialize + ?Sized> { value: &'a T, @@ -55,45 +85,14 @@ impl<'a, T: serde::Serialize + ?Sized> ValueSerde<'a, T> { cache: OnceLock::new(), } } - - /// Consumes the adapter and moves out the cached snapshot, serializing the value if needed. - /// - /// A serialization failure yields the string `""`. - pub fn into_owned(self) -> ValueOwned { - self.cache - .into_inner() - .unwrap_or_else(|| Self::serialize(self.value)) - } - - /// Immediately serializes the borrowed value into a [`ValueOwned`] snapshot. - /// - /// # Errors - /// - /// Returns an error if the value fails to serialize. - /// - /// # Examples - /// - /// ``` - /// use logforth_core::kv::ValueSerde; - /// - /// let snapshot = ValueSerde::try_serialize("ready").unwrap(); - /// assert_eq!(snapshot.view().to_str(), Some("ready")); - /// ``` - pub fn try_serialize(value: &'a T) -> Result { - value.serialize(ValueSerializer).map_err(|err| err.0) - } - - fn serialize(value: &'a T) -> ValueOwned { - Self::try_serialize(value) - .unwrap_or_else(|err| ValueOwned::str(format!("", err.message()))) - } } impl Deref for ValueSerde<'_, T> { type Target = ValueOwned; fn deref(&self) -> &Self::Target { - self.cache.get_or_init(|| Self::serialize(self.value)) + self.cache + .get_or_init(|| ValueOwned::from_serde(self.value)) } } @@ -105,12 +104,6 @@ impl fmt::Debug for ValueSerde<'_, T> { } } -impl From> for ValueOwned { - fn from(value: ValueSerde<'_, T>) -> Self { - value.into_owned() - } -} - impl LogValue for ValueSerde<'_, T> { fn log_value(&self) -> Value<'_> { Value::lazy_owned(self) diff --git a/logforth/src/lib.rs b/logforth/src/lib.rs index c2f158df..04f6b2dd 100644 --- a/logforth/src/lib.rs +++ b/logforth/src/lib.rs @@ -76,7 +76,7 @@ //! | `layout-*` | Additional output formats. | //! | `diagnostic-*` | Diagnostic context from traces or task-local values. | //! | `filter-rustlog` | Filtering with `RUST_LOG` directives. | -//! | `serde` | `kv::ValueSerde` and `serde::Serialize` for [`kv`] types. | +//! | `serde` | `ValueOwned::from_serde`, `kv::ValueSerde`, and `serde::Serialize` for [`kv`] types. | //! | `starter-log` | Starter pack: `starter_log`, `bridge-log`, `filter-rustlog`, text/JSON, and `append-file`. | //! | `bridge-log` | `log` facade adapter (`LogBridge`). | //! | `bridge-log-serde` | Structured `log/kv_serde` value bridging in `bridge-log`. | diff --git a/tests-integration/tests/bridge_test/log.rs b/tests-integration/tests/bridge_test/log.rs index c12deef7..f880d342 100644 --- a/tests-integration/tests/bridge_test/log.rs +++ b/tests-integration/tests/bridge_test/log.rs @@ -25,7 +25,6 @@ use log::kv::VisitSource; use logforth::bridge::log::LogBridge; use logforth::filter::rustlog::RustLogFilterBuilder; use logforth::kv::ValueOwned; -use logforth::kv::ValueSerde; use logforth::kv::ValueView; use logforth::record::Level; use logforth::record::LevelFilter; @@ -302,8 +301,8 @@ fn fallible_kv_source_and_failing_display_never_panic() { assert_eq!(fields.get("first").unwrap().to_u64(), Some(7)); }); - assert!(ValueSerde::try_serialize(&FailingDisplay).is_err()); - let fallback = ValueSerde::new(&FailingDisplay).into_owned(); + assert!(ValueOwned::try_from_serde(&FailingDisplay).is_err()); + let fallback = ValueOwned::from_serde(&FailingDisplay); bridge.log( &log::Record::builder() .key_values(&[("failure", Value::from_display(&FailingDisplay))]) diff --git a/tests-integration/tests/core_test/kv.rs b/tests-integration/tests/core_test/kv.rs index 62f1b8c9..57c3a0f9 100644 --- a/tests-integration/tests/core_test/kv.rs +++ b/tests-integration/tests/core_test/kv.rs @@ -426,7 +426,6 @@ fn lazy_serde_skips_rejected_records_and_memoizes_across_dispatches() { }; assert_eq!(count(value.view()), Some(42)); assert_eq!(count(value.view()), Some(42)); - assert_eq!(count(value.into_owned().view()), Some(42)); assert_eq!(calls.0.load(Ordering::Relaxed), 2); assert_eq!( @@ -470,7 +469,7 @@ fn serde_captures_structured_trees_and_degrades_gracefully_on_failure() { numeric_map: BTreeMap::from([(200, "ok")]), }; - let owned = ValueSerde::try_serialize(&payload).unwrap(); + let owned = ValueOwned::try_from_serde(&payload).unwrap(); let root = owned.view().to_map().unwrap(); assert!(matches!(root.get("unit").unwrap(), ValueView::None)); @@ -528,7 +527,7 @@ fn serde_captures_structured_trees_and_degrades_gracefully_on_failure() { assert_eq!(numeric_map.get("200").unwrap().to_str(), Some("ok")); // Round-trip `ValueOwned`, `KeyValues`, `DebugValue`, and `DisplayValue` through `Serialize`. - let reserialized = ValueSerde::try_serialize(&owned).unwrap(); + let reserialized = ValueOwned::try_from_serde(&owned).unwrap(); assert_eq!( reserialized .view() @@ -544,28 +543,28 @@ fn serde_captures_structured_trees_and_degrades_gracefully_on_failure() { (Key::new("disp"), Value::display(&"plain")), ]; let serialized_kvs = - ValueSerde::try_serialize(&KeyValues::from(fmt_entries.as_slice())).unwrap(); + ValueOwned::try_from_serde(&KeyValues::from(fmt_entries.as_slice())).unwrap(); let kvs_map = serialized_kvs.view().to_map().unwrap(); assert_eq!(kvs_map.get("dbg").unwrap().to_str(), Some("42")); assert_eq!(kvs_map.get("disp").unwrap().to_str(), Some("plain")); assert_eq!( - ValueSerde::try_serialize(&DebugValue::new(&7_u8)) + ValueOwned::try_from_serde(&DebugValue::new(&7_u8)) .unwrap() .view() .to_str(), Some("7") ); assert_eq!( - ValueOwned::from(ValueSerde::new(&DisplayValue::new(&"ok"))) + ValueOwned::from_serde(&DisplayValue::new(&"ok")) .view() .to_str(), Some("ok") ); // Fallible `Serialize` implementations return `Err` or a non-panicking placeholder string. - let err = ValueSerde::try_serialize(&FallibleSerialize).unwrap_err(); + let err = ValueOwned::try_from_serde(&FallibleSerialize).unwrap_err(); assert_eq!(err.message(), "cannot serialize secret"); - let fallback = ValueSerde::new(&FallibleSerialize).into_owned(); + let fallback = ValueOwned::from_serde(&FallibleSerialize); assert_eq!( fallback.view().to_str(), Some("")