Repository navigation
Conversation
Structured logging call sites frequently pass filesystem paths, OS strings, network addresses, mutable references, and standard numeric wrappers directly in `["key" = value]` fields or owned diagnostic contexts. Without built-in `LogValue` and `From` implementations, callers had to convert paths and network addresses manually or wrap every site in `Value::display`. Implement `LogValue` in `logforth-core` for `&mut T`, `Wrapping<T>`, `Saturating<T>`, `OsStr`, `OsString`, `std::ffi::os_str::Display<'_>`, `Path`, `PathBuf`, `std::path::Display<'_>`, and the six `std::net` IP and socket address types, along with matching `From` implementations on `ValueOwned` for `OsString`, `PathBuf`, `std::net` addresses, `Wrapping<T>`, and `Saturating<T>`. Valid UTF-8 paths and OS strings borrow directly as `ValueView::BorrowedStr` (and move existing heap buffers into `ValueOwned` without reallocation), while non-UTF-8 inputs format lossily through `DisplayValue` without allocating on synchronous paths or failing serialization. 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::LogValueinlogforth-corefor&mut T,std::num::{Wrapping, Saturating},OsStr,OsString,std::ffi::os_str::Display<'_>,Path,PathBuf,std::path::Display<'_>, andstd::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}.From<T> for kv::ValueOwnedconversions forOsString,PathBuf,std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},Wrapping<T>, andSaturating<T>.tests-integrationacross UTF-8 and non-UTF-8 paths/OS strings, display adapters, mutable references, numeric wrappers, and network addresses, and updateCHANGELOG.md.Design Notes
PathandOsStrinputs project directly toValue::str(ValueView::BorrowedStr), andFrom<PathBuf>/From<OsString>reuse the existingStringbuffer without reallocating when valid UTF-8.PathandOsStrinputs fall back to a private&'a OsStrvariant insideValueandDisplayValue, preserving the 32-byte size ofValueandValueViewon 64-bit targets while formatting lossily without synchronous heap allocations or serialization errors.