pub struct Headers { /* private fields */ }
Expand description
A structure for keeping relationship between the headers and their positions
Implementations
sourceimpl Headers
impl Headers
sourcepub fn get_field<'r>(&self, row: &'r Row, field: &str) -> Option<&'r str>
pub fn get_field<'r>(&self, row: &'r Row, field: &str) -> Option<&'r str>
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);
sourcepub fn add(&mut self, colname: &str) -> bool
pub fn add(&mut self, colname: &str) -> bool
Adds a new header.
Returns wether the header was added or not.
use csvsc::{Headers, Row};
let mut h: Headers = Row::from(vec!["name"]).into();
h.add("value");
assert_eq!(h, Row::from(vec!["name", "value"]).into());
assert!(!h.add("name"));
assert_eq!(h, Row::from(vec!["name", "value"]).into());
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn as_row(&self) -> &Row
sourcepub fn into_row(self) -> Row
pub fn into_row(self) -> Row
Consumes this Headers object and returns the underlaying Row containing the names.
sourcepub fn index(&self, field: &str) -> Option<usize>
pub fn index(&self, field: &str) -> Option<usize>
Obtains the index of the given field in the headers
pub fn contains_key(&self, field: &str) -> bool
pub fn iter(&self) -> StringRecordIter<'_>
Trait Implementations
sourceimpl From<StringRecord> for Headers
impl From<StringRecord> for Headers
impl StructuralPartialEq for Headers
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more