Trait mzdata::params::ParamValue

source ·
pub trait ParamValue {
Show 18 methods // Required methods fn is_empty(&self) -> bool; fn is_i64(&self) -> bool; fn is_f64(&self) -> bool; fn is_buffer(&self) -> bool; fn is_str(&self) -> bool; fn to_f64(&self) -> Result<f64, ParamValueParseError>; fn to_i64(&self) -> Result<i64, ParamValueParseError>; fn to_str(&self) -> Cow<'_, str>; fn to_buffer(&self) -> Result<Cow<'_, [u8]>, ParamValueParseError>; fn parse<T: FromStr>(&self) -> Result<T, T::Err>; fn as_bytes(&self) -> Cow<'_, [u8]>; fn as_ref(&self) -> ValueRef<'_>; fn data_len(&self) -> usize; // Provided methods fn is_numeric(&self) -> bool { ... } fn to_f32(&self) -> Result<f32, ParamValueParseError> { ... } fn to_i32(&self) -> Result<i32, ParamValueParseError> { ... } fn to_u64(&self) -> Result<u64, ParamValueParseError> { ... } fn as_str(&self) -> Cow<'_, str> { ... }
}
Expand description

Access a parameter’s value, with specific coercion rules and eager type conversion.

Required Methods§

source

fn is_empty(&self) -> bool

Check if the value is empty

source

fn is_i64(&self) -> bool

Check if the value is an integer

source

fn is_f64(&self) -> bool

Check if the value is a floating point number explicitly. An integral number might still be usable as a floating point number

source

fn is_buffer(&self) -> bool

Check if the value is an arbitrary buffer

source

fn is_str(&self) -> bool

Check if the value is stored as an explicit string. All variants can be coerced to a string.

source

fn to_f64(&self) -> Result<f64, ParamValueParseError>

Get the value as an f64, if possible

source

fn to_i64(&self) -> Result<i64, ParamValueParseError>

Get the value as an i64, if possible

source

fn to_str(&self) -> Cow<'_, str>

Get the value as a string

source

fn to_buffer(&self) -> Result<Cow<'_, [u8]>, ParamValueParseError>

Get the value as a byte buffer, if possible.

The intent here is distinct from ParamValue::as_bytes. The byte buffer represents the byte representation of the native value, while ParamValue::as_bytes is a byte string of the string representation.

source

fn parse<T: FromStr>(&self) -> Result<T, T::Err>

Convert the value’s string representation to T if possible

source

fn as_bytes(&self) -> Cow<'_, [u8]>

Convert the value to a byte string, the bytes of the string representation.

source

fn as_ref(&self) -> ValueRef<'_>

Get a reference to the stored value

source

fn data_len(&self) -> usize

Provided Methods§

source

fn is_numeric(&self) -> bool

Check if the value is of either numeric type.

source

fn to_f32(&self) -> Result<f32, ParamValueParseError>

Get the value as an f32, if possible

source

fn to_i32(&self) -> Result<i32, ParamValueParseError>

Get the value as an i32, if possible

source

fn to_u64(&self) -> Result<u64, ParamValueParseError>

Get the value as an u64, if possible

source

fn as_str(&self) -> Cow<'_, str>

Get the value as a string, possibly borrowed

Object Safety§

This trait is not object safe.

Implementors§