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
Primitive(PrimitiveType)
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]
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
impl RefUnwindSafe for ValueType
impl Send for ValueType
impl Sync for ValueType
impl Unpin for ValueType
impl UnwindSafe for ValueType
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DynClone for T where
T: Clone,
[src]
T: Clone,
pub fn __clone_box(&self, Private) -> *mut ()
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,