Skip to content

refactor(core): restore ValueOwned serde constructors and keep ValueSerde lazy-only - #334

Merged
tisonkun merged 2 commits into
mainfrom
refactor/value-serde-try-serialize
Dec 3, 2026
Merged

tisonkun merged 2 commits into
mainfrom
refactor/value-serde-try-serialize

Conversation

@tisonkun

@tisonkun tisonkun commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Restore ValueOwned::from_serde and ValueOwned::try_from_serde (behind the serde feature) in logforth-core for eager owned conversion of serde::Serialize values.
  • Narrow kv::ValueSerde to a pure lazy-initialization field wrapper (ValueSerde::new, Deref<Target = ValueOwned>, LogValue, and Debug), removing into_owned, try_into_owned, and From<ValueSerde<'_, T>> for ValueOwned.
  • Use ValueOwned::from_serde directly in logforth-bridge-log instead of allocating a temporary OnceLock via ValueSerde, and update workspace docs, integration tests, and CHANGELOG.md.

Design Notes

  • Separating eager owned construction (ValueOwned::{from_serde, try_from_serde}) from lazy field capture (ValueSerde::new) eliminates duplicate ValueOwned constructors, avoids constructing an unused OnceLock on eager paths, prevents accidental eager serialization through Into<ValueOwned>, and guarantees that every ValueSerde instance represents a single lazy snapshot.

Test Plan

  • cargo x check
  • cargo x test
  • cargo x lint

…ry_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<ValueOwned, Error>` so each `ValueSerde` instance strictly represents a single memoized lazy snapshot.

Signed-off-by: tison <wander4096@gmail.com>
…erde 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<Target = ValueOwned>`, `LogValue`, and `Debug`) without eager conversion methods.

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun tisonkun changed the title refactor(core): replace ValueSerde::try_into_owned with ValueSerde::try_serialize refactor(core): restore ValueOwned serde constructors and keep ValueSerde lazy-only Dec 3, 2026
@tisonkun
tisonkun merged commit 7fffc0f into main Dec 3, 2026
10 checks passed
@tisonkun
tisonkun deleted the refactor/value-serde-try-serialize branch December 3, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant