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 enums 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

A text entry.

An integer entry.

An unsigned integer entry.

A long entry.

An unsigned long entry.

A floating point entry.

A double precision floating point entry.

A boolean entry.

A character entry.

A missing or invalid entry.

Methods

impl DataEntry
[src]

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");

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);

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 using String::from(). For example the conversion shown in the third example of this docstring.
  • DataType::Character into DataType::Boolean.
  • Anything except DataType::Text into DataType::Character. This can be somewhat circumvented by converting to DataType::Text and then into DataType::Character.
  • Any signed numerical type into an unsigned one.
  • DataType::Long into DataType::Integer.
  • DataType::ULong into DataType::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]

Formats the value using the given formatter. Read more

impl Clone for DataEntry
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for DataEntry
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialOrd for DataEntry
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

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]

The resulting type after applying the + operator.

Performs the + operation.

impl Sub for DataEntry
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl Mul for DataEntry
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl Div for DataEntry
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl From<i8> for DataEntry
[src]

Performs the conversion.

impl From<u8> for DataEntry
[src]

Performs the conversion.

impl From<i16> for DataEntry
[src]

Performs the conversion.

impl From<u16> for DataEntry
[src]

Performs the conversion.

impl From<i32> for DataEntry
[src]

Performs the conversion.

impl From<u32> for DataEntry
[src]

Performs the conversion.

impl From<i64> for DataEntry
[src]

Performs the conversion.

impl From<u64> for DataEntry
[src]

Performs the conversion.

impl From<f32> for DataEntry
[src]

Performs the conversion.

impl From<f64> for DataEntry
[src]

Performs the conversion.

impl From<bool> for DataEntry
[src]

Performs the conversion.

impl From<char> for DataEntry
[src]

Performs the conversion.

impl From<String> for DataEntry
[src]

Performs the conversion.

impl<'a> From<&'a String> for DataEntry
[src]

Performs the conversion.

impl<'a> From<&'a str> for DataEntry
[src]

Performs the conversion.

Auto Trait Implementations

impl Send for DataEntry

impl Sync for DataEntry