Expand description
§Polyvalue
Single concrete type for representing values of different types
This crate was built for use in a parser, where the type of a value is not known until runtime. Please open an issue if you have any suggestions for improvement.
It provides a new type, Value
, which is an enum around a set of types implementing
a common trait, ValueTrait
.
All types will also implement all of the following: Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Serialize, Deserialize, Default
The following types are provided:
Bool
: Wraps abool
Int
: Wraps ani64
Float
: Wraps anf64
Fixed
: Wraps anfpdec::Decimal
, a fixed-point decimal typeCurrency
: Wraps aFixed
and adds a currency symbolStr
: Wraps aString
Array
: Wraps aVec<Value>
, providing an ordered setObject
: Wraps aBTreeMap<Value, Value>
, providing a key-value store
A set of traits for performing operations on values is also provided:
ArithmeticOperationExt
: Operations such as addition, subtraction, etc.BooleanOperationExt
: Equality, comparisons, as well as AND and ORBitwiseOperationExt
: Bitwise operations such as AND, OR, XOR, etc.IndexingOperationExt
: Indexing into arrays, objects, ranges, and stringsIndexingOperationExt
: Indexing mutably into arrays and objects
Note that while indexing into strings is supported, it is not provided through the IndexOperationExt
trait.
This is because we return substrings references, which have additional constraints. See Str
for more information.
Re-exports§
pub use fpdec;
Modules§
- Operations
- Types
Macros§
- Generates a Fixed from a decimal literal
Structs§
- Main value type This is an enum that can hold any of the supported value types
Enums§
- This type is used for all errors that can be returned by Polyvalue
- Main value type This is an enum that can hold any of the supported value types
- The set of types that can be used as values Bool, Fixed, Float, Currency, Int, String, Array, Object represent real types whereas Numeric, Collection, and Any are virtual types representing a set of types
Traits§
- A trait that all values must implement It enforces a set of common traits and accessors