Struct Value

Source
pub struct Value<'v>(/* private fields */);
Expand description

An anonymous captured value that can be serialized or formatted.

Implementations§

Source§

impl<'v> Value<'v>

Source

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

Capture a displayable value.

Source

pub fn from_display(value: &'v impl Display) -> Value<'v>

Get a displayable value.

This method can be used instead of Value::capture_display when the value can’t satisfy the 'static bound.

Source

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

Capture a debuggable value.

Source

pub fn from_debug(value: &'v impl Debug) -> Value<'v>

Get a debuggable value.

This method can be used instead of Value::capture_debug when the value can’t satisfy the 'static bound.

Source

pub fn capture_serde(value: &'v (impl Serialize + 'static)) -> Value<'v>

Capture a serializable value.

Source

pub fn from_serde(value: &'v impl Serialize) -> Value<'v>

Get a serializable value.

This method can be used instead of Value::capture_serde when the value can’t satisfy the 'static bound.

Source

pub fn capture_sval(value: &'v (impl Value + 'static)) -> Value<'v>

Capture a serializable value.

Source

pub fn from_sval(value: &'v impl Value) -> Value<'v>

Get a serializable value.

This method can be used instead of Value::capture_sval when the value can’t satisfy the 'static bound.

Source

pub fn capture_error(value: &'v (impl Error + 'static)) -> Value<'v>

Capture an error.

Source

pub fn from_any(value: &'v impl ToValue) -> Value<'v>

Capture a convertible type.

Source

pub fn null() -> Value<'v>

The absence of any meaningful value.

Source

pub fn is_null(&self) -> bool

Whether the value is null.

Source

pub fn by_ref<'b>(&'b self) -> Value<'b>

Get a new value, borrowing data from this one.

Source

pub fn cast<'a, T>(self) -> Option<T>
where T: FromValue<'v>,

Attempt to convert this value into an owned instance of T.

This may involve downcasting, serializing, or parsing depending on the implementation of FromValue.

Source

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

Attempt to downcast this value into a borrowed instance of T.

This method should be used as a potential optimization, but can’t be relied upon to always return Some. If any internal buffering happens between owned and borrowed value conversions then the internal captured type will change.

Source

pub fn parse<T>(&self) -> Option<T>
where T: FromStr,

Attempt to parse an instance of T from this value.

If the value is an internally captured string then it will be parsed directly. If the value is not a string then it will be formatted into one and then parsed.

Source

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

Try get a borrowed string value.

Source

pub fn to_borrowed_error(&self) -> Option<&'v (dyn Error + 'static)>

Try get a borrowed error value.

Source

pub fn as_f64(&self) -> f64

Get a lossy binary floating point value.

If the value is numeric then it will be converted into an f64 using as conversions. If the value is not numeric then this method will attempt to parse an f64 from it. If the value can’t be parsed then f64::NAN is returned.

Source§

impl<'v> Value<'v>

Source

pub fn to_f64_sequence(&self) -> Option<Vec<f64>>

Get a sequence of binary floating points from a captured sequence of values.

If the value is a sequence then Some is returned. Each element will be converted into a f64 in the same way as Value::as_f64. If the value is not a sequence then None is returned.

For more advanced or specific conversion cases, use serde or sval.

Source§

impl<'v> Value<'v>

Source

pub fn to_owned(&self) -> OwnedValue

Get an owned value from this one.

Source

pub fn to_shared(&self) -> OwnedValue

Get an owned value from this one, internally storing an Arc for cheap cloning.

Source

pub fn to_cow_str(&self) -> Option<Cow<'v, str>>

Try get a string from this value.

If the value is a captured string then Some(Cow::Borrowed) will be returned. If the value is a string that needs to be buffered through a serialization framework then Some(Cow::Owned) is returned. In other cases None is returned.

Trait Implementations§

Source§

impl<'v> Clone for Value<'v>

Source§

fn clone(&self) -> Value<'v>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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, 'a, const N: usize> From<&'v [&'a str; N]> for Value<'v>

Source§

fn from(value: &'v [&'a str; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'v, const N: usize> From<&'v [bool; N]> for Value<'v>

Source§

fn from(value: &'v [bool; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'v, const N: usize> From<&'v [f64; N]> for Value<'v>

Source§

fn from(value: &'v [f64; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'v, const N: usize> From<&'v [i128; N]> for Value<'v>

Source§

fn from(value: &'v [i128; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'v, const N: usize> From<&'v [i16; N]> for Value<'v>

Source§

fn from(value: &'v [i16; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'v, const N: usize> From<&'v [i32; N]> for Value<'v>

Source§

fn from(value: &'v [i32; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'v, const N: usize> From<&'v [i64; N]> for Value<'v>

Source§

fn from(value: &'v [i64; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'v, const N: usize> From<&'v [i8; N]> for Value<'v>

Source§

fn from(value: &'v [i8; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'v, const N: usize> From<&'v [isize; N]> for Value<'v>

Source§

fn from(value: &'v [isize; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'v, const N: usize> From<&'v [u128; N]> for Value<'v>

Source§

fn from(value: &'v [u128; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'v, const N: usize> From<&'v [u16; N]> for Value<'v>

Source§

fn from(value: &'v [u16; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'v, const N: usize> From<&'v [u32; N]> for Value<'v>

Source§

fn from(value: &'v [u32; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'v, const N: usize> From<&'v [u64; N]> for Value<'v>

Source§

fn from(value: &'v [u64; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'v, const N: usize> From<&'v [u8; N]> for Value<'v>

Source§

fn from(value: &'v [u8; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'v, const N: usize> From<&'v [usize; N]> for Value<'v>

Source§

fn from(value: &'v [usize; N]) -> Value<'v>

Converts to this type from the input type.
Source§

impl<'a, 'v> From<&'a Cow<'v, str>> for Value<'a>

Source§

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

Converts to this type from the input type.
Source§

impl<'a> From<&'a OwnedValue> for Value<'a>

Source§

fn from(value: &'a OwnedValue) -> Value<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&'a String> for Value<'a>

Source§

fn from(value: &'a String) -> Value<'a>

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<'a, 'v> From<Option<&'a Cow<'v, str>>> for Value<'a>

Source§

fn from(value: Option<&'a Cow<'v, str>>) -> Value<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Option<&'a String>> for Value<'a>

Source§

fn from(value: Option<&'a String>) -> Value<'a>

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

fn from(value: Option<usize>) -> 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<f64> for Value<'v>

Source§

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

Converts to this type from the input type.
Source§

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

Source§

fn from(value: i128) -> 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<u128> for Value<'v>

Source§

fn from(value: u128) -> 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> FromValue<'v> for Value<'v>

Source§

fn from_value(value: Value<'v>) -> Option<Value<'v>>

Perform the conversion.
Source§

impl<'v> Serialize for Value<'v>

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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

Source§

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

Perform the conversion.
Source§

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

Source§

fn stream<'sval, S>(&'sval self, stream: &mut S) -> Result<(), Error>
where S: Stream<'sval> + ?Sized,

Stream this value through a Stream.
Source§

fn tag(&self) -> Option<Tag>

Get the tag of this value, if there is one.
Source§

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

Try convert this value into a boolean.
Source§

fn to_f32(&self) -> Option<f32>

Try convert this value into a 32bit binary floating point number.
Source§

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

Try convert this value into a 64bit binary floating point number.
Source§

fn to_i8(&self) -> Option<i8>

Try convert this value into a signed 8bit integer.
Source§

fn to_i16(&self) -> Option<i16>

Try convert this value into a signed 16bit integer.
Source§

fn to_i32(&self) -> Option<i32>

Try convert this value into a signed 32bit integer.
Source§

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

Try convert this value into a signed 64bit integer.
Source§

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

Try convert this value into a signed 128bit integer.
Source§

fn to_u8(&self) -> Option<u8>

Try convert this value into an unsigned 8bit integer.
Source§

fn to_u16(&self) -> Option<u16>

Try convert this value into an unsigned 16bit integer.
Source§

fn to_u32(&self) -> Option<u32>

Try convert this value into an unsigned 32bit integer.
Source§

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

Try convert this value into an unsigned 64bit integer.
Source§

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

Try convert this value into an unsigned 128bit integer.
Source§

fn to_text(&self) -> Option<&str>

Try convert this value into a text string.
Source§

fn to_binary(&self) -> Option<&[u8]>

Try convert this value into a bitstring.
Source§

impl<'v> ValueRef<'v> for Value<'v>

Source§

fn stream_ref<S>(&self, stream: &mut S) -> Result<(), Error>
where S: Stream<'v> + ?Sized,

Stream this value through a Stream.

Auto Trait Implementations§

§

impl<'v> Freeze for Value<'v>

§

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> Value for T
where T: Value,