Struct csv_core::Writer [] [src]

pub struct Writer { /* fields omitted */ }

A writer for CSV data.

RFC 4180

This writer conforms to RFC 4180 with one exception: it doesn't guarantee that all records written are of the same length. Instead, the onus is on the caller to ensure that all records written are of the same length.

Note that the default configuration of a Writer uses \n for record terminators instead of \r\n as specified by RFC 4180. Use the terminator method on WriterBuilder to set the terminator to \r\n if it's desired.

Methods

impl Writer
[src]

Creates a new CSV writer with the default configuration.

Finish writing CSV data to output.

This must be called when one is done writing CSV data to output. In particular, it will write closing quotes if necessary.

Write a single CSV field from input to output while employing this writer's quoting style.

This returns the result of writing field data, in addition to the number of bytes consumed from input and the number of bytes written to output.

The result of writing field data is either WriteResult::InputEmpty or WriteResult::OutputFull. The former occurs when all bytes in input were copied to output, while the latter occurs when output is too small to fit everything from input. The maximum number of bytes that can be written to output is 2 + (2 * input.len()) because of quoting. (The worst case is a field consisting entirely of quotes.)

Multiple successive calls to field will write more data to the same field. Subsequent fields can be written by calling either delimiter or terminator first.

If this writer's quoting style is QuoteStyle::Necessary, then input should contain the entire field. Otherwise, whether the field needs to be quoted or not cannot be determined.

Write the configured field delimiter to output.

If the output buffer does not have enough room to fit a field delimiter, then nothing is written to output and WriteResult::OutputFull is returned. Otherwise, WriteResult::InputEmpty is returned along with the number of bytes written to output (which is always 1).

Write the configured record terminator to output.

If the output buffer does not have enough room to fit a record terminator, then no part of the terminator is written and WriteResult::OutputFull is returned. Otherwise, WriteResult::InputEmpty is returned along with the number of bytes written to output (which is always 1 or 2).

Returns true if and only if the given byte corresponds to a special byte in this CSV writer's configuration.

Note that this does not take into account this writer's quoting style.

Returns true if and only if we should put the given field data in quotes. This takes the quoting style into account.

Return the delimiter used for this writer.

Return the terminator used for this writer.

Return the quoting style used for this writer.

Return the quote character used for this writer.

Return the escape character used for this writer.

Return whether this writer doubles quotes or not. When the writer does not double quotes, it will escape them using the escape character.

Trait Implementations

impl Clone for Writer
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Writer
[src]

Formats the value using the given formatter.

impl Default for Writer
[src]

Returns the "default value" for a type. Read more