csv_core

Struct WriterBuilder

source
pub struct WriterBuilder { /* private fields */ }
Expand description

A builder for configuring a CSV writer.

This builder permits specifying the CSV delimiter, terminator, quoting style and more.

Implementations§

source§

impl WriterBuilder

source

pub fn new() -> WriterBuilder

Create a new builder for configuring a CSV writer.

source

pub fn build(&self) -> Writer

Builder a CSV writer from this configuration.

source

pub fn delimiter(&mut self, delimiter: u8) -> &mut WriterBuilder

The field delimiter to use when writing CSV.

The default is b','.

source

pub fn terminator(&mut self, term: Terminator) -> &mut WriterBuilder

The record terminator to use when writing CSV.

A record terminator can be any single byte. The default is \n.

Note that RFC 4180 specifies that record terminators should be \r\n. To use \r\n, use the special Terminator::CRLF value.

source

pub fn quote_style(&mut self, style: QuoteStyle) -> &mut WriterBuilder

The quoting style to use when writing CSV.

By default, this is set to QuoteStyle::Necessary, which will only use quotes when they are necessary to preserve the integrity of data.

Note that unless the quote style is set to Never, an empty field is quoted if it is the only field in a record.

source

pub fn quote(&mut self, quote: u8) -> &mut WriterBuilder

The quote character to use when writing CSV.

The default value is b'"'.

source

pub fn escape(&mut self, escape: u8) -> &mut WriterBuilder

The escape character to use when writing CSV.

This is only used when double_quote is set to false.

The default value is b'\\'.

source

pub fn double_quote(&mut self, yes: bool) -> &mut WriterBuilder

The quoting escape mechanism to use when writing CSV.

When enabled (which is the default), quotes are escaped by doubling them. e.g., " escapes to "".

When disabled, quotes are escaped with the escape character (which is \\ by default).

source

pub fn comment(&mut self, comment: Option<u8>) -> &mut WriterBuilder

The comment character that will be used when later reading the file.

If quote_style is set to QuoteStyle::Necessary, a field will be quoted if the comment character is detected anywhere in the field.

The default value is None.

Trait Implementations§

source§

impl Debug for WriterBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for WriterBuilder

source§

fn default() -> WriterBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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.