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:
std::fmt::Debugstd::fmt::DisplayCloneEqPartialEqPartialOrdstd::hash::Hashstd::ops::Addstd::ops::Substd::ops::Mulstd::ops::Divstd::ops::Remnum_traits::Pow<Self>This is required such that we can expect anyValueabletype to work more or less the same.
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§
Sourcefn is_truthy(&self) -> ValueResult<bool, Self>
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.
Sourcefn to_int(&self) -> ValueResult<i32, Self>
fn to_int(&self) -> ValueResult<i32, Self>
Sourcefn to_float(&self) -> ValueResult<f32, Self>
fn to_float(&self) -> ValueResult<f32, Self>
Sourcefn display_numerical(&self) -> ValueResult<String, Self>
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
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.