Repository navigation
Conversation
Add `kv::lazy` (`kv::ValueLazy`) and `kv::serde` (behind the `serde` feature) in `logforth-core::kv` and re-export them through `logforth::kv` so callers can capture lazily computed or serializable fields without spelling out carrier struct constructors or nested `LazyLock` wrappers. `ValueLazy<F>` defers invoking its initializer until first dereference or `Display` formatting and caches the resulting `ValueOwned` snapshot across all dispatches and `Record::to_owned` promotions. 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
kv::lazyandkv::ValueLazyinlogforth-core(re-exported atlogforth::kv) to defer computing expensive structured fields or formatted payload arguments until first inspection and share the cachedValueOwnedsnapshot across dispatches.kv::serde(behind theserdefeature) inlogforth-coreas a concise constructor returningkv::ValueSerde<'_, T>.tests-integrationcovering level and dispatch-filter pruning, multi-dispatch memoization across structured fields and formatted payloads, non-Sendsingle-thread initializers, and uninitializedDebugformatting, and update docs andCHANGELOG.md.Design Notes
ValueLazy<F>,ValueSerde<'a, T>) paired with concisekv::*constructors: BecauseValue<'a>is aCopystack-borrowed carrier, lazy memoizing fields require a caller-stack owner for theirOnceLock<ValueOwned>cache (Value::lazy_owned). Returning named carrier types rather than opaqueimpl LogValuekeepskv::lazyandkv::serdeconst fn, preserves clean rustdoc signatures, and supports conditional trait bounds (Deref<Target = ValueOwned>andDisplayfor anyFnOnce() -> Tincluding!Sendclosures, withLogValuegated onF: Send, mirroringValueSerde'sT: Syncbound).ValueLazy<F>: UsingMutex<Option<F>>alongsideOnceLock<ValueOwned>avoidsunsafe(unsafe_code = "deny"), performs zero heap allocations or syscalls when a record is rejected by level masks or downstreamFilters, and letsFreturn anyT: Into<ValueOwned>directly without unnameable adapter closures.