Struct geng::prelude::log::kv::value::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§

source§

impl<'v> Value<'v>

source

pub fn from_any<T>(value: &'v T) -> Value<'v>
where T: ToValue,

Get a value from a type implementing ToValue.

source

pub fn capture_debug<T>(value: &'v T) -> Value<'v>
where T: Debug + 'static,

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

source

pub fn capture_display<T>(value: &'v T) -> Value<'v>
where T: Display + 'static,

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

source

pub fn from_debug<T>(value: &'v T) -> Value<'v>
where T: Debug,

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

source

pub fn from_display<T>(value: &'v T) -> Value<'v>
where T: Display,

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

source

pub fn from_dyn_debug(value: &'v dyn Debug) -> Value<'v>

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

source

pub fn from_dyn_display(value: &'v dyn Display) -> Value<'v>

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

source

pub fn is<T>(&self) -> bool
where T: 'static,

Check whether this value can be downcast to T.

source

pub fn downcast_ref<T>(&self) -> Option<&T>
where T: 'static,

Try downcast this value to T.

source

pub fn visit(&self, visitor: impl Visit<'v>) -> Result<(), Error>

Inspect this value using a simple visitor.

source§

impl<'v> Value<'v>

source

pub fn to_u64(&self) -> Option<u64>

Try convert this value into a u64.

source

pub fn to_i64(&self) -> Option<i64>

Try convert this value into a i64.

source

pub fn to_u128(&self) -> Option<u128>

Try convert this value into a u128.

source

pub fn to_i128(&self) -> Option<i128>

Try convert this value into a i128.

source

pub fn to_f64(&self) -> Option<f64>

Try convert this value into a f64.

source

pub fn to_char(&self) -> Option<char>

Try convert this value into a char.

source

pub fn to_bool(&self) -> Option<bool>

Try convert this value into a bool.

source§

impl<'v> Value<'v>

source

pub fn to_borrowed_str(&self) -> Option<&str>

Try convert this value into a borrowed string.

Trait Implementations§

source§

impl<'v> Debug for Value<'v>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'v> Display for Value<'v>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'v> From<&'v NonZeroI128> for Value<'v>

source§

fn from(v: &'v NonZeroI128) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<&'v NonZeroU128> for Value<'v>

source§

fn from(v: &'v NonZeroU128) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<&'v i128> for Value<'v>

source§

fn from(value: &'v i128) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<&'v str> for Value<'v>

source§

fn from(value: &'v str) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<&'v u128> for Value<'v>

source§

fn from(value: &'v u128) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<NonZeroI16> for Value<'v>

source§

fn from(value: NonZeroI16) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<NonZeroI32> for Value<'v>

source§

fn from(value: NonZeroI32) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<NonZeroI64> for Value<'v>

source§

fn from(value: NonZeroI64) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<NonZeroI8> for Value<'v>

source§

fn from(value: NonZeroI8) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<NonZeroIsize> for Value<'v>

source§

fn from(value: NonZeroIsize) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<NonZeroU16> for Value<'v>

source§

fn from(value: NonZeroU16) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<NonZeroU32> for Value<'v>

source§

fn from(value: NonZeroU32) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<NonZeroU64> for Value<'v>

source§

fn from(value: NonZeroU64) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<NonZeroU8> for Value<'v>

source§

fn from(value: NonZeroU8) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<NonZeroUsize> for Value<'v>

source§

fn from(value: NonZeroUsize) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<bool> for Value<'v>

source§

fn from(value: bool) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<char> for Value<'v>

source§

fn from(value: char) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<f32> for Value<'v>

source§

fn from(value: f32) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<f64> for Value<'v>

source§

fn from(value: f64) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<i16> for Value<'v>

source§

fn from(value: i16) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<i32> for Value<'v>

source§

fn from(value: i32) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<i64> for Value<'v>

source§

fn from(value: i64) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<i8> for Value<'v>

source§

fn from(value: i8) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<isize> for Value<'v>

source§

fn from(value: isize) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<u16> for Value<'v>

source§

fn from(value: u16) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<u32> for Value<'v>

source§

fn from(value: u32) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<u64> for Value<'v>

source§

fn from(value: u64) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<u8> for Value<'v>

source§

fn from(value: u8) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> From<usize> for Value<'v>

source§

fn from(value: usize) -> Value<'v>

Converts to this type from the input type.
source§

impl<'v> ToValue for Value<'v>

source§

fn to_value(&self) -> Value<'_>

Perform the conversion.

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,