pub struct Value<'v>(/* private fields */);
Expand description
An anonymous captured value that can be serialized or formatted.
Implementations§
Source§impl<'v> Value<'v>
impl<'v> Value<'v>
Sourcepub fn capture_display(value: &'v (impl Display + 'static)) -> Value<'v>
pub fn capture_display(value: &'v (impl Display + 'static)) -> Value<'v>
Capture a displayable value.
Sourcepub fn from_display(value: &'v impl Display) -> Value<'v>
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.
Sourcepub fn capture_debug(value: &'v (impl Debug + 'static)) -> Value<'v>
pub fn capture_debug(value: &'v (impl Debug + 'static)) -> Value<'v>
Capture a debuggable value.
Sourcepub fn from_debug(value: &'v impl Debug) -> Value<'v>
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.
Sourcepub fn capture_serde(value: &'v (impl Serialize + 'static)) -> Value<'v>
pub fn capture_serde(value: &'v (impl Serialize + 'static)) -> Value<'v>
Capture a serializable value.
Sourcepub fn from_serde(value: &'v impl Serialize) -> Value<'v>
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.
Sourcepub fn capture_sval(value: &'v (impl Value + 'static)) -> Value<'v>
pub fn capture_sval(value: &'v (impl Value + 'static)) -> Value<'v>
Capture a serializable value.
Sourcepub fn from_sval(value: &'v impl Value) -> Value<'v>
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.
Sourcepub fn capture_error(value: &'v (impl Error + 'static)) -> Value<'v>
pub fn capture_error(value: &'v (impl Error + 'static)) -> Value<'v>
Capture an error.
Sourcepub fn cast<'a, T>(self) -> Option<T>where
T: FromValue<'v>,
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
.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: 'static,
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.
Sourcepub fn parse<T>(&self) -> Option<T>where
T: FromStr,
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.
Sourcepub fn to_borrowed_str(&self) -> Option<&'v str>
pub fn to_borrowed_str(&self) -> Option<&'v str>
Try get a borrowed string value.
Sourcepub fn to_borrowed_error(&self) -> Option<&'v (dyn Error + 'static)>
pub fn to_borrowed_error(&self) -> Option<&'v (dyn Error + 'static)>
Try get a borrowed error value.
Source§impl<'v> Value<'v>
impl<'v> Value<'v>
Sourcepub fn to_f64_sequence(&self) -> Option<Vec<f64>>
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>
impl<'v> Value<'v>
Sourcepub fn to_owned(&self) -> OwnedValue
pub fn to_owned(&self) -> OwnedValue
Get an owned value from this one.
Get an owned value from this one, internally storing an Arc
for cheap cloning.
Sourcepub fn to_cow_str(&self) -> Option<Cow<'v, str>>
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<'a> From<&'a OwnedValue> for Value<'a>
impl<'a> From<&'a OwnedValue> for Value<'a>
Source§fn from(value: &'a OwnedValue) -> Value<'a>
fn from(value: &'a OwnedValue) -> Value<'a>
Source§impl<'v> Serialize for Value<'v>
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,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<'v> Value for Value<'v>
impl<'v> Value for Value<'v>
Source§fn stream<'sval, S>(&'sval self, stream: &mut S) -> Result<(), Error>
fn stream<'sval, S>(&'sval self, stream: &mut S) -> Result<(), Error>
Stream
.