Skip to content

feat(core): implement LogValue and ValueOwned conversions for std types - #333

Closed
tisonkun wants to merge 1 commit into
mainfrom
feat/std-log-value
Closed

tisonkun wants to merge 1 commit into
mainfrom
feat/std-log-value

Conversation

@tisonkun

@tisonkun tisonkun commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Implement kv::LogValue in logforth-core for &mut T, std::num::{Wrapping, Saturating}, OsStr, OsString, std::ffi::os_str::Display<'_>, Path, PathBuf, std::path::Display<'_>, and std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}.
  • Implement matching From<T> for kv::ValueOwned conversions for OsString, PathBuf, std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}, Wrapping<T>, and Saturating<T>.
  • Add integration coverage in tests-integration across UTF-8 and non-UTF-8 paths/OS strings, display adapters, mutable references, numeric wrappers, and network addresses, and update CHANGELOG.md.

Design Notes

  • Valid UTF-8 Path and OsStr inputs project directly to Value::str (ValueView::BorrowedStr), and From<PathBuf> / From<OsString> reuse the existing String buffer without reallocating when valid UTF-8.
  • Non-UTF-8 Path and OsStr inputs fall back to a private &'a OsStr variant inside Value and DisplayValue, preserving the 32-byte size of Value and ValueView on 64-bit targets while formatting lossily without synchronous heap allocations or serialization errors.

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>
@tisonkun tisonkun closed this Dec 2, 2026
@tisonkun
tisonkun deleted the feat/std-log-value branch December 2, 2026 18:36
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