pub struct ContextValue(/* private fields */);
Expand description
Represents a type of value that can be stored in the log context.
The ContextValue
type is a flexible container designed to hold various kinds of data
that can be associated with a log entry. It supports primitive types, strings, and
more complex types such as those implementing std::fmt::Debug
, std::fmt::Display
,
std::error::Error
, or serde::Serialize
.
This allows for rich and structured logging, enabling developers to attach meaningful context to log messages.
§Examples
use context_logger::ContextValue;
let value = ContextValue::display("example string");
let number = ContextValue::from(42);
let debug_value = ContextValue::debug(vec![1, 2, 3]);
Implementations§
Source§impl ContextValue
impl ContextValue
Sourcepub fn serde<S>(value: S) -> Self
pub fn serde<S>(value: S) -> Self
Creates a context value from a serde::Serialize
.
Sourcepub fn display<T>(value: T) -> Self
pub fn display<T>(value: T) -> Self
Creates a context value from a std::fmt::Display
.
Sourcepub fn debug<T>(value: T) -> Self
pub fn debug<T>(value: T) -> Self
Creates a context value from a std::fmt::Debug
.
Sourcepub fn error<T>(value: T) -> Self
pub fn error<T>(value: T) -> Self
Creates a context value from a std::error::Error
.
Sourcepub fn as_log_value(&self) -> Value<'_>
pub fn as_log_value(&self) -> Value<'_>
Represents a context value that can be used with the log
crate.
Trait Implementations§
Source§impl Debug for ContextValue
impl Debug for ContextValue
Source§impl Display for ContextValue
impl Display for ContextValue
Source§impl From<&str> for ContextValue
impl From<&str> for ContextValue
Source§impl From<String> for ContextValue
impl From<String> for ContextValue
Source§impl From<bool> for ContextValue
impl From<bool> for ContextValue
Source§impl From<char> for ContextValue
impl From<char> for ContextValue
Source§impl From<f64> for ContextValue
impl From<f64> for ContextValue
Source§impl From<i128> for ContextValue
impl From<i128> for ContextValue
Source§impl From<i16> for ContextValue
impl From<i16> for ContextValue
Source§impl From<i32> for ContextValue
impl From<i32> for ContextValue
Source§impl From<i64> for ContextValue
impl From<i64> for ContextValue
Source§impl From<i8> for ContextValue
impl From<i8> for ContextValue
Source§impl From<u128> for ContextValue
impl From<u128> for ContextValue
Source§impl From<u16> for ContextValue
impl From<u16> for ContextValue
Source§impl From<u32> for ContextValue
impl From<u32> for ContextValue
Source§impl From<u64> for ContextValue
impl From<u64> for ContextValue
Auto Trait Implementations§
impl Freeze for ContextValue
impl !RefUnwindSafe for ContextValue
impl Send for ContextValue
impl Sync for ContextValue
impl Unpin for ContextValue
impl !UnwindSafe for ContextValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more