Struct CSVWriter

Source
pub struct CSVWriter<T>
where T: Write + Sized,
{ /* 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>

Source

pub fn new(output: T) -> Self

Creates a new writer using the default dialect.

Source

pub fn with_dialect(self, dialect: Dialect) -> Self

Sets the dialect to use

Source

pub fn with_column_names(self, columns: &[&str]) -> Self

Sets the column names to use as the header

Source

pub fn write_header(&mut self) -> Result<(), CSVError>

Ensures that the header (if specified and present) is written to the file.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<T> Freeze for CSVWriter<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for CSVWriter<T>
where T: RefUnwindSafe,

§

impl<T> Send for CSVWriter<T>
where T: Send,

§

impl<T> Sync for CSVWriter<T>
where T: Sync,

§

impl<T> Unpin for CSVWriter<T>
where T: Unpin,

§

impl<T> UnwindSafe for CSVWriter<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> MaybeInto<U> for T
where U: MaybeFrom<T>,

Source§

fn maybe_into(self) -> Option<U>

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.