pub enum PrimitiveType {
Bool,
Char,
Number(NumberType),
Unit,
}Expand description
Represents primitive value types
Variants§
Implementations§
Source§impl PrimitiveType
impl PrimitiveType
pub fn is_bool(&self) -> bool
pub fn is_char(&self) -> bool
pub fn is_number(&self) -> bool
pub fn is_unit(&self) -> bool
pub fn to_number_type(&self) -> Option<NumberType>
Sourcepub fn from_type_name(tname: &str) -> Result<Self, ParseError>
pub fn from_type_name(tname: &str) -> Result<Self, ParseError>
Constructs a primitive value type from a Rust-based type string similar
to what you would find from std::any::type_name
§Examples
use entity::{PrimitiveType as PVT, NumberType as NT};
assert_eq!(
PVT::from_type_name("bool").unwrap(),
PVT::Bool,
);
assert_eq!(
PVT::from_type_name("char").unwrap(),
PVT::Char,
);
assert_eq!(
PVT::from_type_name("u8").unwrap(),
PVT::Number(NT::U8),
);
assert_eq!(
PVT::from_type_name("()").unwrap(),
PVT::Unit,
);Trait Implementations§
Source§impl Clone for PrimitiveType
impl Clone for PrimitiveType
Source§fn clone(&self) -> PrimitiveType
fn clone(&self) -> PrimitiveType
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PrimitiveType
impl Debug for PrimitiveType
Source§impl Default for PrimitiveType
impl Default for PrimitiveType
Source§impl Display for PrimitiveType
impl Display for PrimitiveType
Source§impl<'a> From<&'a Primitive> for PrimitiveType
impl<'a> From<&'a Primitive> for PrimitiveType
Source§impl From<Primitive> for PrimitiveType
impl From<Primitive> for PrimitiveType
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 PrimitiveType
impl FromStr for PrimitiveType
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parses a primitive value type
§Examples
use entity::{PrimitiveType as PVT, NumberType as NT};
use strum::ParseError;
use std::str::FromStr;
assert_eq!(PVT::from_str("bool").unwrap(), PVT::Bool);
assert_eq!(PVT::from_str("char").unwrap(), PVT::Char);
assert_eq!(PVT::from_str("u32").unwrap(), PVT::Number(NT::U32));
assert_eq!(PVT::from_str("number:u32").unwrap(), PVT::Number(NT::U32));
assert_eq!(PVT::from_str("unit").unwrap(), PVT::Unit);
assert_eq!(PVT::from_str("unknown").unwrap_err(), ParseError::VariantNotFound);Source§type Err = ParseError
type Err = ParseError
The associated error which can be returned from parsing.
Source§impl PartialEq for PrimitiveType
impl PartialEq for PrimitiveType
impl Copy for PrimitiveType
impl Eq for PrimitiveType
impl StructuralPartialEq for PrimitiveType
Auto Trait Implementations§
impl Freeze for PrimitiveType
impl RefUnwindSafe for PrimitiveType
impl Send for PrimitiveType
impl Sync for PrimitiveType
impl Unpin for PrimitiveType
impl UnwindSafe for PrimitiveType
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