Struct log::kv::Value [−][src]
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
impl<'v> Value<'v>
[src]
pub fn from_any<T>(value: &'v T) -> Self where
T: ToValue,
[src]
T: ToValue,
Get a value from a type implementing ToValue
.
pub fn capture_debug<T>(value: &'v T) -> Self where
T: Debug + 'static,
[src]
T: Debug + 'static,
Get a value from a type implementing std::fmt::Debug
.
pub fn capture_display<T>(value: &'v T) -> Self where
T: Display + 'static,
[src]
T: Display + 'static,
Get a value from a type implementing std::fmt::Display
.
pub fn from_debug<T>(value: &'v T) -> Self where
T: Debug,
[src]
T: Debug,
Get a value from a type implementing std::fmt::Debug
.
pub fn from_display<T>(value: &'v T) -> Self where
T: Display,
[src]
T: Display,
Get a value from a type implementing std::fmt::Display
.
pub fn from_dyn_debug(value: &'v dyn Debug) -> Self
[src]
Get a value from a dynamic std::fmt::Debug
.
pub fn from_dyn_display(value: &'v dyn Display) -> Self
[src]
Get a value from a dynamic std::fmt::Display
.
pub fn is<T: 'static>(&self) -> bool
[src]
Check whether this value can be downcast to T
.
pub fn downcast_ref<T: 'static>(&self) -> Option<&T>
[src]
Try downcast this value to T
.
impl<'v> Value<'v>
[src]
pub fn to_u64(&self) -> Option<u64>
[src]
Try convert this value into a u64
.
pub fn to_i64(&self) -> Option<i64>
[src]
Try convert this value into a i64
.
pub fn to_u128(&self) -> Option<u128>
[src]
Try convert this value into a u128
.
pub fn to_i128(&self) -> Option<i128>
[src]
Try convert this value into a i128
.
pub fn to_f64(&self) -> Option<f64>
[src]
Try convert this value into a f64
.
pub fn to_char(&self) -> Option<char>
[src]
Try convert this value into a char
.
pub fn to_bool(&self) -> Option<bool>
[src]
Try convert this value into a bool
.
impl<'v> Value<'v>
[src]
pub fn to_borrowed_str(&self) -> Option<&str>
[src]
Try convert this value into a borrowed string.
Trait Implementations
impl<'v> Debug for Value<'v>
[src]
impl<'v> Display for Value<'v>
[src]
impl<'v> From<&'v str> for Value<'v>
[src]
impl<'v> From<bool> for Value<'v>
[src]
impl<'v> From<char> for Value<'v>
[src]
impl<'v> From<f32> for Value<'v>
[src]
impl<'v> From<f64> for Value<'v>
[src]
impl<'v> From<i128> for Value<'v>
[src]
impl<'v> From<i16> for Value<'v>
[src]
impl<'v> From<i32> for Value<'v>
[src]
impl<'v> From<i64> for Value<'v>
[src]
impl<'v> From<i8> for Value<'v>
[src]
impl<'v> From<isize> for Value<'v>
[src]
impl<'v> From<u128> for Value<'v>
[src]
impl<'v> From<u16> for Value<'v>
[src]
impl<'v> From<u32> for Value<'v>
[src]
impl<'v> From<u64> for Value<'v>
[src]
impl<'v> From<u8> for Value<'v>
[src]
impl<'v> From<usize> for Value<'v>
[src]
impl<'v> ToValue for Value<'v>
[src]
Auto Trait Implementations
impl<'v> !RefUnwindSafe for Value<'v>
impl<'v> !Send for Value<'v>
impl<'v> !Sync for Value<'v>
impl<'v> Unpin for Value<'v>
impl<'v> !UnwindSafe for Value<'v>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,