Struct DataColumn

Source
pub struct DataColumn {
    pub name: Option<String>,
    /* private fields */
}
Expand description

A data column consisting of Strings.

Fields§

§name: Option<String>

The name associated with the DataColumn.

Implementations§

Source§

impl DataColumn

Source

pub fn empty() -> DataColumn

Constructs an empty data column.

Source

pub fn len(&self) -> usize

Gets the length of the data column.

Source

pub fn data(&self) -> &Vec<String>

Gets an immutable reference to the underlying data.

Source

pub fn categories(&self) -> Option<HashMap<String, usize>>

Gets an immutable reference to the categories Option.

Source

pub fn update_categories(&mut self)

Update the categories set using the current data.

§Examples
use rusty_data::datatable::DataColumn;

let mut dc = DataColumn::empty();

dc.push("Class1".to_string());
dc.push("Class2".to_string());
dc.push("Class2".to_string());

dc.update_categories();
let categories = dc.categories().unwrap();

// Note that `contains` requires a reference so we pass an &str.
assert!(categories.contains_key("Class2"));
assert_eq!(categories.len(), 2);
Source

pub fn numeric_category_data<T: Zero + One>( &self, ) -> Result<Vec<Vec<T>>, DataError>

Produce a numerical vector representation of the category data.

§Examples
use rusty_data::datatable::DataColumn;

let mut dc = DataColumn::empty();

dc.push("Class1".to_string());
dc.push("Class2".to_string());
dc.push("Class2".to_string());

dc.update_categories();

let data = dc.numeric_category_data::<f64>().unwrap();

println!("The data is: {:?}", data);
Source

pub fn push(&mut self, val: String)

Pushes a new &str to the column.

Source

pub fn get_as<T: FromStr>(&self, idx: usize) -> Result<T, DataError>

Try to get the element at the index as the requested type.

§Failures
  • DataCastError : The element at the given index could not be parsed to this type.
Source

pub fn shrink_to_fit(&mut self)

Shrink the column to fit the data.

Source

pub fn into_vec<T: FromStr>(self) -> Result<Vec<T>, DataError>

Consumes self and returns a Vec of the requested type.

§Failures
  • DataCastError : Returned when the data cannot be parsed to the requested type.
Source

pub fn cast<T: FromStr>(&self) -> Option<Vec<T>>

Cast the data to the requested type.

Returns a Vec of the requested type wrapped in an option.

Source

pub fn into_iter_cast<U>( self, ) -> Map<IntoIter<String>, fn(String) -> Result<U, <U as FromStr>::Err>>
where U: FromStr,

Consumes self and returns an iterator which parses the data to the specified type returning results.

The iterator will return a result on next() detailing the outcome of the parse.

Trait Implementations§

Source§

impl Index<usize> for DataColumn

Source§

type Output = String

The returned type after indexing.
Source§

fn index(&self, idx: usize) -> &String

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.