Enum entity::ValueType[][src]

pub enum ValueType {
    List(Box<ValueType>),
    Map(Box<ValueType>),
    Optional(Box<ValueType>),
    Primitive(PrimitiveType),
    Text,
    Custom,
}

Represents value types (primitive or complex). Assumes that complex types will contain the same inner type and does not vary

Variants

List(Box<ValueType>)
Optional(Box<ValueType>)
Primitive(PrimitiveType)
Text
Custom

Implementations

impl ValueType[src]

pub fn is_primitive_type(&self) -> bool[src]

pub fn to_primitive_type(&self) -> Option<PrimitiveType>[src]

pub fn from_type_name(name: &str) -> Result<Self, ParseError>[src]

Constructs a value type from a Rust-based type string similar to what you would find from std::any::type_name

Examples

use entity::{ValueType as VT, PrimitiveType as PVT, NumberType as NT};

assert_eq!(
    VT::from_type_name("u8").expect("one"),
    VT::Primitive(PVT::Number(NT::U8)),
);

assert_eq!(
    VT::from_type_name("std::vec::Vec<std::string::String>").expect("two"),
    VT::List(Box::from(VT::Text)),
);

assert_eq!(
    VT::from_type_name("Vec<Option<u8>>").expect("three"),
    VT::List(Box::from(VT::Optional(Box::from(VT::Primitive(PVT::Number(NT::U8)))))),
);

assert_eq!(
    VT::from_type_name("HashMap<String, u8>").expect("four"),
    VT::Map(Box::from(VT::Primitive(PVT::Number(NT::U8)))),
);

Trait Implementations

impl Clone for ValueType[src]

impl Debug for ValueType[src]

impl Default for ValueType[src]

fn default() -> Self[src]

Returns default value type of primitive unit

impl Display for ValueType[src]

impl Eq for ValueType[src]

impl<'a> From<&'a Value> for ValueType[src]

fn from(v: &'a Value) -> Self[src]

Produces the type of the referenced value by recursively iterating through complex types, assuming that the first value in types like list represent the entire set, defaulting to a primitive unit if a complex value does not have any items

impl From<NumberType> for ValueType[src]

fn from(t: NumberType) -> Self[src]

Converts number type (subclass of primitive type) to a value type

impl From<PrimitiveType> for ValueType[src]

fn from(t: PrimitiveType) -> Self[src]

Converts primitive value type to a value type

impl From<Value> for ValueType[src]

impl FromStr for ValueType[src]

type Err = ParseError

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Self, Self::Err>[src]

Parses a string delimited by colons into a nested value type

Examples

use entity::{ValueType as VT, PrimitiveType as PVT, NumberType as NT};
use strum::ParseError;
use std::str::FromStr;

assert_eq!(VT::from_str("char").unwrap(), VT::Primitive(PVT::Char));
assert_eq!(VT::from_str("u32").unwrap(), VT::Primitive(PVT::Number(NT::U32)));
assert_eq!(VT::from_str("number:u32").unwrap(), VT::Primitive(PVT::Number(NT::U32)));
assert_eq!(VT::from_str("primitive:number:u32").unwrap(), VT::Primitive(PVT::Number(NT::U32)));
assert_eq!(VT::from_str("list:u32").unwrap(), VT::List(Box::from(VT::Primitive(PVT::Number(NT::U32)))));
assert_eq!(VT::from_str("list:number:u32").unwrap(), VT::List(Box::from(VT::Primitive(PVT::Number(NT::U32)))));
assert_eq!(VT::from_str("list:primitive:number:u32").unwrap(), VT::List(Box::from(VT::Primitive(PVT::Number(NT::U32)))));
assert_eq!(VT::from_str("unknown").unwrap_err(), ParseError::VariantNotFound);

impl PartialEq<ValueType> for ValueType[src]

impl StructuralEq for ValueType[src]

impl StructuralPartialEq for ValueType[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DynClone for T where
    T: Clone
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.