logo

Struct log::kv::Value

source · []
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

Get a value from a type implementing ToValue.

Get a value from a type implementing std::fmt::Debug.

Get a value from a type implementing std::fmt::Display.

Get a value from a type implementing std::fmt::Debug.

Get a value from a type implementing std::fmt::Display.

Get a value from a dynamic std::fmt::Debug.

Get a value from a dynamic std::fmt::Display.

Check whether this value can be downcast to T.

Try downcast this value to T.

Inspect this value using a simple visitor.

Try convert this value into a u64.

Try convert this value into a i64.

Try convert this value into a u128.

Try convert this value into a i128.

Try convert this value into a f64.

Try convert this value into a char.

Try convert this value into a bool.

Try convert this value into a borrowed string.

Trait Implementations

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Perform the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.