pub enum ValueType {
List(Box<ValueType>),
Map(Box<ValueType>),
Optional(Box<ValueType>),
Primitive(PrimitiveType),
Text,
Custom,
}Expand description
Represents value types (primitive or complex). Assumes that complex types will contain the same inner type and does not vary
Variants§
List(Box<ValueType>)
Map(Box<ValueType>)
Optional(Box<ValueType>)
Primitive(PrimitiveType)
Text
Custom
Implementations§
Source§impl ValueType
impl ValueType
pub fn is_primitive_type(&self) -> bool
pub fn to_primitive_type(&self) -> Option<PrimitiveType>
Sourcepub fn from_type_name(name: &str) -> Result<Self, ParseError>
pub fn from_type_name(name: &str) -> Result<Self, ParseError>
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§
Source§impl From<NumberType> for ValueType
impl From<NumberType> for ValueType
Source§fn from(t: NumberType) -> Self
fn from(t: NumberType) -> Self
Converts number type (subclass of primitive type) to a value type
Source§impl From<PrimitiveType> for ValueType
impl From<PrimitiveType> for ValueType
Source§fn from(t: PrimitiveType) -> Self
fn from(t: PrimitiveType) -> Self
Converts primitive value type to a value type
Source§impl FromStr for ValueType
impl FromStr for ValueType
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
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);Source§type Err = ParseError
type Err = ParseError
The associated error which can be returned from parsing.
impl Eq for ValueType
impl StructuralPartialEq for ValueType
Auto Trait Implementations§
impl Freeze for ValueType
impl RefUnwindSafe for ValueType
impl Send for ValueType
impl Sync for ValueType
impl Unpin for ValueType
impl UnwindSafe for ValueType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more