pub trait Valueable: Debug + Display + Clone + Eq + PartialEq + PartialOrd + Hash + Add + Sub + Mul + Div + Rem + Pow<Self> {
    // Required methods
    fn is_truthy(&self) -> ValueResult<bool, Self>;
    fn to_int(&self) -> ValueResult<i32, Self>;
    fn to_float(&self) -> ValueResult<f32, Self>;
    fn display_numerical(&self) -> ValueResult<String, Self>;
}
Expand description

A trait to allow “extension” of the Value enum.

Sometimes, the basic types supported by Value are not enough and the newtype pattern is required to extend it. Registering this newtype as Valueable means that it supports all common operations associated with a Value.

Besides implementing the required methods. Any type that implements Valueable is required to implement the following traits:

Most of the required traits can be automatically derived. You can use wagon_macros::ValueOps (or it’s associated methods) to automatically derive implementations for all the operative traits (Add, Sub, etc).

Required Methods§

source

fn is_truthy(&self) -> ValueResult<bool, Self>

Is this value seen as true or false?

§Errors

Should return an error if this value can not be converted into a bool.

source

fn to_int(&self) -> ValueResult<i32, Self>

Convert the value to a regular i32.

§Errors

Should return an error if this value can not be converted into an i32.

source

fn to_float(&self) -> ValueResult<f32, Self>

Convert the value to a regular f32.

§Errors

Should return an error if this value can not be converted into an f32.

source

fn display_numerical(&self) -> ValueResult<String, Self>

Get a string representation of the value, as if it were a number.

§Errors

Should return an error if this value can not be displayed as a number

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T: ToValue<T> + From<Value<T>> + Clone + Eq + PartialEq + PartialOrd + Debug + Display + Hash + Add + Sub + Mul + Div + Rem + Pow<T>> Valueable for T

source§

impl<T: Valueable> Valueable for Value<T>