Crate polyvalue

source ·
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 a bool
  • Int : Wraps an i64
  • Float : Wraps an f64
  • Fixed : Wraps an fpdec::Decimal, a fixed-point decimal type
  • Currency : Wraps a Fixed and adds a currency symbol
  • Str : Wraps a String
  • Array : Wraps a Vec<Value>, providing an ordered set
  • Object : Wraps a BTreeMap<Value, Value>, providing a key-value store

A set of traits for performing operations on values is also provided:

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§

Modules§

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