refactor!: rework TaskLocalDiagnostic#234
Conversation
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors task-local diagnostics to store structured key/value data using the core KeyOwned/ValueOwned types, improving ergonomics for attaching context to async tasks and aligning task-local diagnostics with the core KV model.
Changes:
- Reworked
TaskLocalDiagnosticto storeVec<(KeyOwned, ValueOwned)>and updatedFutureExt::with_task_local_contextto accept any(K, V)whereK: Into<KeyOwned>andV: Into<ValueOwned>. - Extended core KV types with additional
Fromconversions and madeKeyView/ValueViewCopyto simplify usage in visitors/serialization. - Minor doc wording updates and small serialization call-site adjustments in JSON-based layouts.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| layouts/json/src/lib.rs | Adjusts KV-to-JSON conversion call site for ValueView. |
| layouts/google-cloud-logging/src/lib.rs | Same KV-to-JSON conversion adjustment for GCL layout fields/labels. |
| filters/rustlog/src/lib.rs | Doc wording tweak for crate-level documentation link text. |
| diagnostics/task-local/src/lib.rs | Stores owned KV pairs in task-local storage; makes with_task_local_context more flexible. |
| core/src/kv.rs | Adds From impls for owned KV types; makes KeyView/ValueView Copy. |
| appenders/syslog/src/lib.rs | Doc wording tweak for crate-level documentation link text. |
| appenders/file/src/append.rs | Doc wording tweak for crate-level documentation link text. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: tison <wander4096@gmail.com>
There was a problem hiding this comment.
Not sure if we can ensure View and Borrowed Key/Value always Copy but I suggest it is the right design and we should keep it as much as possible.
| impl<F> Visitor for F | ||
| where | ||
| F: FnMut(KeyView, ValueView) -> Result<(), Error>, | ||
| { | ||
| fn visit(&mut self, key: KeyView, value: ValueView) -> Result<(), Error> { | ||
| self(key, value) | ||
| } | ||
| } |
There was a problem hiding this comment.
Explicitly should be better. But this impl looks very common to support; as in this PR:
diag.visit(&mut |key: KeyView<'_>, value: ValueView<'_>| {
assert_eq!(key.as_str(), "key");
assert_eq!(value.to_str().unwrap(), "value");
Ok(())
})
.unwrap();
No description provided.