Trait ValueConverter

Source
pub trait ValueConverter: Sized {
    // Required method
    fn from_value(value: &Value) -> Result<Self>;
}
Expand description

Trait for converting Values to native types.

This trait enables automatic conversion between Value instances and native Rust types. It is implemented for common types like f64, String, bool, DateTime, and Vec<T>.

This trait is automatically implemented for common types and is typically used internally by the function registration macros in crate::macros.

Required Methods§

Source

fn from_value(value: &Value) -> Result<Self>

Convert a Value to this native type.

§Arguments
  • value - The value to convert
§Returns

Returns a Result<Self> containing the converted value or an error if conversion fails.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ValueConverter for bool

Source§

fn from_value(value: &Value) -> Result<Self>

Source§

impl ValueConverter for f64

Source§

fn from_value(value: &Value) -> Result<Self>

Source§

impl ValueConverter for String

Source§

fn from_value(value: &Value) -> Result<Self>

Source§

impl ValueConverter for DateTime

Source§

fn from_value(value: &Value) -> Result<Self>

Source§

impl<T: ValueConverter> ValueConverter for Vec<T>

Source§

fn from_value(value: &Value) -> Result<Self>

Implementors§