Repository navigation
feat(core): unify serde field capture into lazy ValueSerde - #329
Merged
Merged
Conversation
Add `Value::serde`, `SerdeValue`, `ValueView::Serde`, and `ValueView::to_serde` in `logforth-core` so callers can borrow `serde::Serialize` values on the stack without allocation, skip serialization when a dispatch `Filter` rejects a record, stream directly into `serde::Serializer` outputs such as `JsonLayout` without an intermediate `ValueOwned` tree, and expand structured values across `OpentelemetryLog`, `LogfmtLayout`, `Journald`, and `Record::to_owned()`. Implement `LogValue` and `From<...> for ValueOwned` for `Path`, `PathBuf` (plus `Box<Path>` and `Cow<'_, Path>` on `ValueOwned`), and `std::net` IP and socket address types (`IpAddr`, `Ipv4Addr`, `Ipv6Addr`, `SocketAddr`, `SocketAddrV4`, and `SocketAddrV6`), keeping `Value<'a>` at 24 bytes (`Copy + Send + Sync`) on 64-bit targets. Signed-off-by: tison <wander4096@gmail.com>
Defer standard-library `Path`, `PathBuf`, and `std::net` `LogValue` and `ValueOwned` implementations to a separate follow-up so this change focuses exclusively on lazy borrowed `Value::serde` (`SerdeValue`, `ValueView::Serde`, and `ValueView::to_serde`). Signed-off-by: tison <wander4096@gmail.com>
Drop the optional `erased-serde` dependency from `logforth-core` and serialize `SerdeValue` through `SerdeValue::try_to_owned`, keeping `logforth-core`'s `serde` feature backed solely by `serde` and sharing identical `ValueSerializer` semantics across synchronous and asynchronous outputs while preserving zero-allocation capture and filter short-circuiting. Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
Replace `Value::serde`, `SerdeValue`, and `ValueView::Serde` with `kv::serde` (`kv::Serde<'a, T>` backed by `&'a T` and `OnceLock<ValueOwned>`), keeping `ValueView` and all downstream layouts and appenders untouched while skipping serialization on rejected records and memoizing materialization across multiple dispatches. Signed-off-by: tison <wander4096@gmail.com>
Replace the private `LazyOwned` trait and `kv::Serde` wrapper struct with standard-library `std::ops::Deref<Target = ValueOwned>` inside `ValueState` and `impl LogValue for std::sync::LazyLock<ValueOwned, F>`, reducing `kv::serde` to a `LazyLock::new` adapter returning `impl LogValue` with no custom structs, traits, or extra `Value` constructors. Signed-off-by: tison <wander4096@gmail.com>
Replace unstable `OnceLock::get_or_try_init` on `ValueSerde` with stable `OnceLock::{get, get_or_init}` (`serialize` / `try_serialize`), implement `Deref<Target = ValueOwned>` and lazy `LogValue` via `ValueState::LazyOwned(&'a (dyn Deref<Target = ValueOwned> + Sync))`, relax `+ Sync` to the `LogValue` impl so `!Sync` serializable types work with `to_owned` and `try_to_owned`, and align `logforth-bridge-log`, docs, changelog, and integration tests.
Signed-off-by: tison <wander4096@gmail.com>
…Serde Expose `Value::lazy_owned` on `Value` for `&'a (dyn Deref<Target = ValueOwned> + Sync)` cells, unify `&self` caching across `ValueSerde` (`Deref`, `LogValue`, `to_owned`, and `try_to_owned`), add consuming `into_owned` and `try_into_owned` conversions (plus `From<ValueSerde<'_, T>>` for `ValueOwned`), remove `Clone` on `ValueSerde`, and align crate documentation, changelog, and integration tests. Signed-off-by: tison <wander4096@gmail.com>
…erde Back `ValueSerde` directly with `OnceLock<ValueOwned>` and remove `to_owned` and `try_to_owned`, leaving `new`, `into_owned`, and `try_into_owned` alongside `Deref<Target = ValueOwned>`, `From<ValueSerde<'_, T>>` for `ValueOwned`, and `LogValue`. Signed-off-by: tison <wander4096@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Unify structured
serdefield capture inlogforth-core(behind theserdefeature) intokv::ValueSerde<'a, T>and exposeValue::lazy_ownedfor lazily initializedValueOwnedfields, replacingValueOwned::{from_serde, try_from_serde}with a single adapter across borrowed logging and owned snapshots.Value::lazy_owned(&'a (dyn Deref<Target = ValueOwned> + Sync))onValue<'a>so lazyValueOwnedcontainers (such asstd::sync::LazyLock<ValueOwned, F>andValueSerde) stay unevaluated until a dispatch inspects or clones the field.kv::ValueSerde<'a, T: serde::Serialize + ?Sized>backed byOnceLock<ValueOwned>withconst fn new(&'a T),into_owned(self) -> ValueOwned,try_into_owned(self) -> Result<ValueOwned, Error>,Deref<Target = ValueOwned>,From<ValueSerde<'_, T>>forValueOwned, andLogValue(where T: Sync).into_owned.Deref,into_owned, andtry_into_ownedavailable for!SyncSerializetypes (such asDebugValue,DisplayValue, andlog::kv::Value), and migratelogforth-bridge-logtoValueSerde::new(&value).into_owned().