pub struct Headers { /* private fields */ }
Expand description
A structure for keeping relationship between the headers and their positions
Implementations§
Source§impl 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§
Source§impl From<StringRecord> for Headers
impl From<StringRecord> for Headers
impl StructuralPartialEq for Headers
Auto Trait Implementations§
impl Freeze for Headers
impl RefUnwindSafe for Headers
impl Send for Headers
impl Sync for Headers
impl Unpin for Headers
impl UnwindSafe for Headers
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more