[−][src]Struct csvsc::Headers
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,