pub struct CSVWriter<T>{ /* private fields */ }
Expand description
Flexible CSV writer, wherein one can specify the dialect and optional column headers
Implementations§
Source§impl<T: Write + Sized> CSVWriter<T>
impl<T: Write + Sized> CSVWriter<T>
Sourcepub fn with_dialect(self, dialect: Dialect) -> Self
pub fn with_dialect(self, dialect: Dialect) -> Self
Sets the dialect to use
Sourcepub fn with_column_names(self, columns: &[&str]) -> Self
pub fn with_column_names(self, columns: &[&str]) -> Self
Sets the column names to use as the header
Sourcepub fn write_header(&mut self) -> Result<(), CSVError>
pub fn write_header(&mut self) -> Result<(), CSVError>
Ensures that the header (if specified and present) is written to the file.
Sourcepub fn write_line<R: AsRef<str>>(
&mut self,
fields: &[R],
) -> Result<(), CSVError>
pub fn write_line<R: AsRef<str>>( &mut self, fields: &[R], ) -> Result<(), CSVError>
Raw low-level write of a set of fields to this file in simple iteration order. This does NOT check against previous lines to ensure the fields are the same length as priors.
Sourcepub fn write_fields<K: AsRef<str>, V: AsRef<str>>(
&mut self,
fields: &BTreeMap<K, V>,
) -> Result<(), CSVError>
pub fn write_fields<K: AsRef<str>, V: AsRef<str>>( &mut self, fields: &BTreeMap<K, V>, ) -> Result<(), CSVError>
Write the set of fields to the CSV file. You must have already provided a set of headers/columns
or else this function will fail with a CSVErrorType::MissingHeaderError
.
It will write the fields in the order defined by the columns.
Note: It is NOT required for the fields map to have every header/column within it. Any missing fields will be replaced with an empty string.