Enum raccoon::entry::DataEntry [−][src]
pub enum DataEntry { Text(String), Integer(i32), UInteger(u32), Long(i64), ULong(u64), Float(f32), Double(f64), Boolean(bool), Character(char), NA, }
A cell-like data entry. Note that DataEntry::Integer
, DataEntry::UInteger
, and DataEntry::Float
, are only
added for convenience. Due to how Rust enum
s are stored, using a DataEntry::Integer
does not actually reduce
the memory footprint versus DataEntry::Long
.
See raccoon::entry
for more details on memory efficiency.
Variants
Text(String)
A text entry.
Integer(i32)
An integer entry.
UInteger(u32)
An unsigned integer entry.
Long(i64)
A long entry.
ULong(u64)
An unsigned long entry.
Float(f32)
A floating point entry.
Double(f64)
A double precision floating point entry.
Boolean(bool)
A boolean entry.
Character(char)
A character entry.
NA
A missing or invalid entry.
Methods
impl DataEntry
[src]
impl DataEntry
pub fn internal_type(&self) -> &str
[src]
pub fn internal_type(&self) -> &str
Retrieves the internal type of the entry. This can be one of the following:
String
,i32
,u32
,i64
,u64
,f32
,f64
,bool
,char
,na
.
Examples
let entry = DataEntry::Text("some text".to_owned()); assert_eq!(entry.internal_type(), "String"); let entry = DataEntry::Character('a'); assert_eq!(entry.internal_type(), "char"); let entry = DataEntry::Integer(-234); assert_eq!(entry.internal_type(), "i32");
Note that the internal type does not always correspond with the constructing type:
let entry = DataEntry::from(2u8); assert_eq!(entry.internal_type(), "u32");
pub fn data_type(&self) -> DataType
[src]
pub fn data_type(&self) -> DataType
Retrieves the type of the entry as a DataType
.
Example
let entry = DataEntry::from(true); assert_eq!(entry.data_type(), DataType::Boolean); let entry = DataEntry::from(-2i8); assert_eq!(entry.data_type(), DataType::Integer);
pub fn convert_to(&self, data_type: &DataType) -> DataEntry
[src]
pub fn convert_to(&self, data_type: &DataType) -> DataEntry
Convert this entry into another data type. Note this does not modify the initial entry itself but returns a new entry with the desired type.
Note that some data types cannot be converted into one another as the conversion makes no sense. This results in
DataType::NA
entries. The conversion from numerical types into boolean values is performed by checking
equality with 0.
Conversions that result in DataType::NA
DataType::Text
into another type that cannot be parsed into another type usingString::from()
. For example the conversion shown in the third example of this docstring.DataType::Character
intoDataType::Boolean
.- Anything except
DataType::Text
intoDataType::Character
. This can be somewhat circumvented by converting toDataType::Text
and then intoDataType::Character
. - Any signed numerical type into an unsigned one.
DataType::Long
intoDataType::Integer
.DataType::ULong
intoDataType::UInteger
.
Examples
A working conversion:
let entry = DataEntry::from(true); let new_entry = entry.convert_to(&DataType::Integer); assert_eq!(new_entry, DataEntry::Integer(1));
A working yet lossy conversion:
// build double precision floating point DataEntry let entry = DataEntry::from(123.456f64); assert_eq!(entry.data_type(), DataType::Double); // convert to single precision floating point let new_entry = entry.convert_to(&DataType::Float); assert_eq!(new_entry.data_type(), DataType::Float); assert_eq!(new_entry, DataEntry::Float(123.456f32));
A conversion that makes no sense:
let entry = DataEntry::from("word"); let new_entry = entry.convert_to(&DataType::Character); assert_eq!(new_entry, DataEntry::NA);
Trait Implementations
impl Debug for DataEntry
[src]
impl Debug for DataEntry
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Clone for DataEntry
[src]
impl Clone for DataEntry
fn clone(&self) -> DataEntry
[src]
fn clone(&self) -> DataEntry
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl PartialEq for DataEntry
[src]
impl PartialEq for DataEntry
fn eq(&self, other: &DataEntry) -> bool
[src]
fn eq(&self, other: &DataEntry) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &DataEntry) -> bool
[src]
fn ne(&self, other: &DataEntry) -> bool
This method tests for !=
.
impl PartialOrd for DataEntry
[src]
impl PartialOrd for DataEntry
fn partial_cmp(&self, other: &DataEntry) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &DataEntry) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &DataEntry) -> bool
[src]
fn lt(&self, other: &DataEntry) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &DataEntry) -> bool
[src]
fn le(&self, other: &DataEntry) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &DataEntry) -> bool
[src]
fn gt(&self, other: &DataEntry) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &DataEntry) -> bool
[src]
fn ge(&self, other: &DataEntry) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Add for DataEntry
[src]
impl Add for DataEntry
type Output = DataEntry
The resulting type after applying the +
operator.
fn add(self, other: DataEntry) -> Self::Output
[src]
fn add(self, other: DataEntry) -> Self::Output
Performs the +
operation.
impl Sub for DataEntry
[src]
impl Sub for DataEntry
type Output = DataEntry
The resulting type after applying the -
operator.
fn sub(self, other: DataEntry) -> Self::Output
[src]
fn sub(self, other: DataEntry) -> Self::Output
Performs the -
operation.
impl Mul for DataEntry
[src]
impl Mul for DataEntry
type Output = DataEntry
The resulting type after applying the *
operator.
fn mul(self, rhs: DataEntry) -> Self::Output
[src]
fn mul(self, rhs: DataEntry) -> Self::Output
Performs the *
operation.
impl Div for DataEntry
[src]
impl Div for DataEntry
type Output = DataEntry
The resulting type after applying the /
operator.
fn div(self, rhs: DataEntry) -> Self::Output
[src]
fn div(self, rhs: DataEntry) -> Self::Output
Performs the /
operation.
impl From<i8> for DataEntry
[src]
impl From<i8> for DataEntry
impl From<u8> for DataEntry
[src]
impl From<u8> for DataEntry
impl From<i16> for DataEntry
[src]
impl From<i16> for DataEntry
impl From<u16> for DataEntry
[src]
impl From<u16> for DataEntry
impl From<i32> for DataEntry
[src]
impl From<i32> for DataEntry
impl From<u32> for DataEntry
[src]
impl From<u32> for DataEntry
impl From<i64> for DataEntry
[src]
impl From<i64> for DataEntry
impl From<u64> for DataEntry
[src]
impl From<u64> for DataEntry
impl From<f32> for DataEntry
[src]
impl From<f32> for DataEntry
impl From<f64> for DataEntry
[src]
impl From<f64> for DataEntry
impl From<bool> for DataEntry
[src]
impl From<bool> for DataEntry
impl From<char> for DataEntry
[src]
impl From<char> for DataEntry
impl From<String> for DataEntry
[src]
impl From<String> for DataEntry
impl<'a> From<&'a String> for DataEntry
[src]
impl<'a> From<&'a String> for DataEntry
impl<'a> From<&'a str> for DataEntry
[src]
impl<'a> From<&'a str> for DataEntry