[][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 new() -> Headers[src]

Creates an empty Headers object.

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 = Row::from(vec!["id", "val"]).into();
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 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 = Row::from(vec!["name"]).into();

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

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

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

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

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

pub fn into_row(self) -> Row[src]

Consumes this Headers object and returns the underlaying Row containing the names.

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 From<Headers> for Row[src]

impl From<StringRecord> 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.