pub struct Value<'v> { /* private fields */ }
Expand description
A value in a structured key-value pair.
Capturing values
There are a few ways to capture a value:
- Using the
Value::capture_*
methods. - Using the
Value::from_*
methods. - Using the
ToValue
trait. - Using the standard
From
trait.
Using the Value::capture_*
methods
Value
offers a few constructor methods that capture values of different kinds.
These methods require a T: 'static
to support downcasting.
use log::kv::Value;
let value = Value::capture_debug(&42i32);
assert_eq!(Some(42), value.to_i64());
Using the Value::from_*
methods
Value
offers a few constructor methods that capture values of different kinds.
These methods don’t require T: 'static
, but can’t support downcasting.
use log::kv::Value;
let value = Value::from_debug(&42i32);
assert_eq!(None, value.to_i64());
Using the ToValue
trait
The ToValue
trait can be used to capture values generically.
It’s the bound used by Source
.
let value = 42i32.to_value();
assert_eq!(Some(42), value.to_i64());
use log::kv::ToValue;
let value = (&42i32 as &dyn Debug).to_value();
assert_eq!(None, value.to_i64());
Using the standard From
trait
Standard types that implement ToValue
also implement From
.
use log::kv::Value;
let value = Value::from(42i32);
assert_eq!(Some(42), value.to_i64());
Implementations§
source§impl<'v> Value<'v>
impl<'v> Value<'v>
sourcepub fn from_any<T>(value: &'v T) -> Selfwhere
T: ToValue,
pub fn from_any<T>(value: &'v T) -> Selfwhere T: ToValue,
Get a value from a type implementing ToValue
.
sourcepub fn capture_debug<T>(value: &'v T) -> Selfwhere
T: Debug + 'static,
pub fn capture_debug<T>(value: &'v T) -> Selfwhere T: Debug + 'static,
Get a value from a type implementing std::fmt::Debug
.
sourcepub fn capture_display<T>(value: &'v T) -> Selfwhere
T: Display + 'static,
pub fn capture_display<T>(value: &'v T) -> Selfwhere T: Display + 'static,
Get a value from a type implementing std::fmt::Display
.
sourcepub fn capture_error<T>(err: &'v T) -> Selfwhere
T: Error + 'static,
pub fn capture_error<T>(err: &'v T) -> Selfwhere T: Error + 'static,
Get a value from an error.
sourcepub fn capture_serde<T>(value: &'v T) -> Selfwhere
T: Serialize + 'static,
pub fn capture_serde<T>(value: &'v T) -> Selfwhere T: Serialize + 'static,
Get a value from a type implementing serde::Serialize
.
sourcepub fn capture_sval<T>(value: &'v T) -> Selfwhere
T: Value + 'static,
pub fn capture_sval<T>(value: &'v T) -> Selfwhere T: Value + 'static,
Get a value from a type implementing sval::Value
.
sourcepub fn from_debug<T>(value: &'v T) -> Selfwhere
T: Debug,
pub fn from_debug<T>(value: &'v T) -> Selfwhere T: Debug,
Get a value from a type implementing std::fmt::Debug
.
sourcepub fn from_display<T>(value: &'v T) -> Selfwhere
T: Display,
pub fn from_display<T>(value: &'v T) -> Selfwhere T: Display,
Get a value from a type implementing std::fmt::Display
.
sourcepub fn from_serde<T>(value: &'v T) -> Selfwhere
T: Serialize,
pub fn from_serde<T>(value: &'v T) -> Selfwhere T: Serialize,
Get a value from a type implementing serde::Serialize
.
sourcepub fn from_sval<T>(value: &'v T) -> Selfwhere
T: Value,
pub fn from_sval<T>(value: &'v T) -> Selfwhere T: Value,
Get a value from a type implementing sval::Value
.
sourcepub fn from_dyn_debug(value: &'v dyn Debug) -> Self
pub fn from_dyn_debug(value: &'v dyn Debug) -> Self
Get a value from a dynamic std::fmt::Debug
.
sourcepub fn from_dyn_display(value: &'v dyn Display) -> Self
pub fn from_dyn_display(value: &'v dyn Display) -> Self
Get a value from a dynamic std::fmt::Display
.
sourcepub fn from_dyn_error(err: &'v (dyn Error + 'static)) -> Self
pub fn from_dyn_error(err: &'v (dyn Error + 'static)) -> Self
Get a value from a dynamic error.
sourcepub fn downcast_ref<T: 'static>(&self) -> Option<&T>
pub fn downcast_ref<T: 'static>(&self) -> Option<&T>
Try downcast this value to T
.
Trait Implementations§
source§impl<'v> From<&'v NonZeroI128> for Value<'v>
impl<'v> From<&'v NonZeroI128> for Value<'v>
source§fn from(v: &'v NonZeroI128) -> Value<'v>
fn from(v: &'v NonZeroI128) -> Value<'v>
source§impl<'v> From<&'v NonZeroU128> for Value<'v>
impl<'v> From<&'v NonZeroU128> for Value<'v>
source§fn from(v: &'v NonZeroU128) -> Value<'v>
fn from(v: &'v NonZeroU128) -> Value<'v>
source§impl<'v> From<NonZeroI16> for Value<'v>
impl<'v> From<NonZeroI16> for Value<'v>
source§fn from(value: NonZeroI16) -> Self
fn from(value: NonZeroI16) -> Self
source§impl<'v> From<NonZeroI32> for Value<'v>
impl<'v> From<NonZeroI32> for Value<'v>
source§fn from(value: NonZeroI32) -> Self
fn from(value: NonZeroI32) -> Self
source§impl<'v> From<NonZeroI64> for Value<'v>
impl<'v> From<NonZeroI64> for Value<'v>
source§fn from(value: NonZeroI64) -> Self
fn from(value: NonZeroI64) -> Self
source§impl<'v> From<NonZeroIsize> for Value<'v>
impl<'v> From<NonZeroIsize> for Value<'v>
source§fn from(value: NonZeroIsize) -> Self
fn from(value: NonZeroIsize) -> Self
source§impl<'v> From<NonZeroU16> for Value<'v>
impl<'v> From<NonZeroU16> for Value<'v>
source§fn from(value: NonZeroU16) -> Self
fn from(value: NonZeroU16) -> Self
source§impl<'v> From<NonZeroU32> for Value<'v>
impl<'v> From<NonZeroU32> for Value<'v>
source§fn from(value: NonZeroU32) -> Self
fn from(value: NonZeroU32) -> Self
source§impl<'v> From<NonZeroU64> for Value<'v>
impl<'v> From<NonZeroU64> for Value<'v>
source§fn from(value: NonZeroU64) -> Self
fn from(value: NonZeroU64) -> Self
source§impl<'v> From<NonZeroUsize> for Value<'v>
impl<'v> From<NonZeroUsize> for Value<'v>
source§fn from(value: NonZeroUsize) -> Self
fn from(value: NonZeroUsize) -> Self
source§impl<'v> Value for Value<'v>
impl<'v> Value for Value<'v>
source§fn stream<'sval, S: Stream<'sval> + ?Sized>(
&'sval self,
stream: &mut S
) -> Result
fn stream<'sval, S: Stream<'sval> + ?Sized>( &'sval self, stream: &mut S ) -> Result
Stream
.