[][src]Struct csvsc::Headers

pub struct Headers { /* fields omitted */ }

A structure for keeping relationship between the headers and their positions

Implementations

impl Headers[src]

pub fn from_row(row: Row) -> Headers[src]

pub fn get_field<'r>(&self, row: &'r Row, field: &str) -> Option<&'r str>[src]

Retrieves a field from a row given it's header name

use csvsc::{Headers, Row};

let headers = Headers::from_row(Row::from(vec!["id", "val"]));
let row = Row::from(vec!["1", "40"]);

assert_eq!(headers.get_field(&row, "id"), Some("1"));
assert_eq!(headers.get_field(&row, "val"), Some("40"));
assert_eq!(headers.get_field(&row, "foo"), None);

pub fn hash(&self, row: &Row, columns: &[String]) -> Result<u64, String>[src]

Creates a hash for the row given as first argument only considering the columns specified by the second argument.

use csvsc::{Headers, Row};

let headers = Headers::from_row(Row::from(vec!["id", "name", "val"]));
let row = Row::from(vec!["1", "juan", "40"]);

dbg!(headers.hash(&row, &["id".to_string(), "name".to_string()]));

If no columns are specified, a random hash is chosen. If a column is not found its name is returned as String wrapped in the Err variant of the return value

pub fn add(&mut self, colname: &str) -> Result<(), ()>[src]

Adds a new header. It'll fail if the header is already present

use csvsc::{Headers, Row};

let mut h = Headers::from_row(Row::from(vec!["name"]));

h.add("value").unwrap();

assert_eq!(h, Headers::from_row(Row::from(vec!["name", "value"])));

assert_eq!(h.add("name"), Err(()));
assert_eq!(h, Headers::from_row(Row::from(vec!["name", "value"])));

pub fn len(&self) -> usize[src]

pub fn as_row(&self) -> &Row[src]

pub fn index(&self, field: &str) -> Option<usize>[src]

Obtains the index of the given field in the headers

pub fn contains_key(&self, field: &str) -> bool[src]

pub fn iter(&self) -> StringRecordIter[src]

Trait Implementations

impl Clone for Headers[src]

impl Debug for Headers[src]

impl PartialEq<Headers> for Headers[src]

impl PartialEq<Headers> for Row[src]

impl StructuralPartialEq for Headers[src]

Auto Trait Implementations

impl RefUnwindSafe for Headers

impl Send for Headers

impl Sync for Headers

impl Unpin for Headers

impl UnwindSafe for Headers

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.