Struct WriterBuilder
pub struct WriterBuilder {
delimiter: u8,
has_header: bool,
quote: u8,
escape: u8,
double_quote: bool,
date_format: Option<String>,
datetime_format: Option<String>,
timestamp_format: Option<String>,
timestamp_tz_format: Option<String>,
time_format: Option<String>,
null_value: Option<String>,
}
Expand description
A CSV writer builder
Fields§
§delimiter: u8
§has_header: bool
§quote: u8
§escape: u8
§double_quote: bool
§date_format: Option<String>
§datetime_format: Option<String>
§timestamp_format: Option<String>
§timestamp_tz_format: Option<String>
§time_format: Option<String>
§null_value: Option<String>
Implementations§
§impl WriterBuilder
impl WriterBuilder
pub fn new() -> WriterBuilder
pub fn new() -> WriterBuilder
Create a new builder for configuring CSV writing options.
To convert a builder into a writer, call WriterBuilder::build
§Example
fn example() -> Writer<File> {
let file = File::create("target/out.csv").unwrap();
// create a builder that doesn't write headers
let builder = WriterBuilder::new().with_header(false);
let writer = builder.build(file);
writer
}
pub fn with_header(self, header: bool) -> WriterBuilder
pub fn with_header(self, header: bool) -> WriterBuilder
Set whether to write the CSV file with a header
pub fn with_delimiter(self, delimiter: u8) -> WriterBuilder
pub fn with_delimiter(self, delimiter: u8) -> WriterBuilder
Set the CSV file’s column delimiter as a byte character
pub fn with_quote(self, quote: u8) -> WriterBuilder
pub fn with_quote(self, quote: u8) -> WriterBuilder
Set the CSV file’s quote character as a byte character
pub fn with_escape(self, escape: u8) -> WriterBuilder
pub fn with_escape(self, escape: u8) -> WriterBuilder
Set the CSV file’s escape character as a byte character
In some variants of CSV, quotes are escaped using a special escape
character like \
(instead of escaping quotes by doubling them).
By default, writing these idiosyncratic escapes is disabled, and is
only used when double_quote
is disabled.
pub fn with_double_quote(self, double_quote: bool) -> WriterBuilder
pub fn with_double_quote(self, double_quote: bool) -> WriterBuilder
Set whether to enable double quote escapes
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).
pub fn double_quote(&self) -> bool
pub fn double_quote(&self) -> bool
Get whether double quote escapes are enabled
pub fn with_date_format(self, format: String) -> WriterBuilder
pub fn with_date_format(self, format: String) -> WriterBuilder
Set the CSV file’s date format
pub fn date_format(&self) -> Option<&str>
pub fn date_format(&self) -> Option<&str>
Get the CSV file’s date format if set, defaults to RFC3339
pub fn with_datetime_format(self, format: String) -> WriterBuilder
pub fn with_datetime_format(self, format: String) -> WriterBuilder
Set the CSV file’s datetime format
pub fn datetime_format(&self) -> Option<&str>
pub fn datetime_format(&self) -> Option<&str>
Get the CSV file’s datetime format if set, defaults to RFC3339
pub fn with_time_format(self, format: String) -> WriterBuilder
pub fn with_time_format(self, format: String) -> WriterBuilder
Set the CSV file’s time format
pub fn time_format(&self) -> Option<&str>
pub fn time_format(&self) -> Option<&str>
Get the CSV file’s datetime time if set, defaults to RFC3339
pub fn with_timestamp_format(self, format: String) -> WriterBuilder
pub fn with_timestamp_format(self, format: String) -> WriterBuilder
Set the CSV file’s timestamp format
pub fn timestamp_format(&self) -> Option<&str>
pub fn timestamp_format(&self) -> Option<&str>
Get the CSV file’s timestamp format if set, defaults to RFC3339
pub fn with_timestamp_tz_format(self, tz_format: String) -> WriterBuilder
pub fn with_timestamp_tz_format(self, tz_format: String) -> WriterBuilder
Set the CSV file’s timestamp tz format
pub fn timestamp_tz_format(&self) -> Option<&str>
pub fn timestamp_tz_format(&self) -> Option<&str>
Get the CSV file’s timestamp tz format if set, defaults to RFC3339
pub fn with_null(self, null_value: String) -> WriterBuilder
pub fn with_null(self, null_value: String) -> WriterBuilder
Set the value to represent null in output
Trait Implementations§
§impl Clone for WriterBuilder
impl Clone for WriterBuilder
§fn clone(&self) -> WriterBuilder
fn clone(&self) -> WriterBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Debug for WriterBuilder
impl Debug for WriterBuilder
§impl Default for WriterBuilder
impl Default for WriterBuilder
§fn default() -> WriterBuilder
fn default() -> WriterBuilder
Auto Trait Implementations§
impl Freeze for WriterBuilder
impl RefUnwindSafe for WriterBuilder
impl Send for WriterBuilder
impl Sync for WriterBuilder
impl Unpin for WriterBuilder
impl UnwindSafe for WriterBuilder
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request