pub struct CsvFormat { /* private fields */ }Expand description
Comma-separated values as RFC 4180 has them: fields separated by ,,
every line ended by CRLF, a field in quotes when it holds the separator,
a quote, CR or LF, inner quotes doubled. Leading and trailing spaces are
kept without quotes.
Cells are written by the export’s CellExport: raw values by default
(numbers with a ., TRUE and FALSE). A summary row is a line like
any other and a cell the row does not export is an empty field, as in
TsvExporter. The header line holds the column titles; header bands
are not written.
The text is UTF-8 with a byte order mark by default, which Excel needs to
read it as UTF-8 (CsvEncoding). A spreadsheet whose decimal separator
is a comma reads ; between fields:
use gpui_kit_grid::{CellExport, CsvEncoding, CsvFormat, GridRow, RawCells};
let format = CsvFormat::new().with_separator(';');
assert_eq!(format.encoding(), CsvEncoding::Utf8WithBom);
// The cells to export with it: `1234,5`.
fn decimal_comma<R: GridRow>() -> CellExport<R> {
CellExport::Raw(RawCells::new().with_decimal_separator(','))
}No protection against formulas: a field that starts with =, +, - or
@ is written as it is (-5 is a number). An application that exports
text its users typed adds a ' with its own CellExport::Custom.
Implementations§
Source§impl CsvFormat
impl CsvFormat
Sourcepub const fn with_separator(self, separator: char) -> Self
pub const fn with_separator(self, separator: char) -> Self
Separates fields with separator: ; for a spreadsheet whose
decimal separator is a comma, with
RawCells::with_decimal_separator(',').
§Panics
If separator is a quote, CR or LF, which no reader tells apart.
Sourcepub const fn with_encoding(self, encoding: CsvEncoding) -> Self
pub const fn with_encoding(self, encoding: CsvEncoding) -> Self
Encodes the text with encoding.
Sourcepub const fn encoding(&self) -> CsvEncoding
pub const fn encoding(&self) -> CsvEncoding
How the text is encoded.
Trait Implementations§
Source§impl<R: GridRow> ExportFormat<R> for CsvFormat
impl<R: GridRow> ExportFormat<R> for CsvFormat
Source§fn export(
&self,
table: &ExportTable<'_, R>,
cells: &CellExport<R>,
out: &mut dyn Write,
control: &ExportControl,
) -> Result<(), ExportError>
fn export( &self, table: &ExportTable<'_, R>, cells: &CellExport<R>, out: &mut dyn Write, control: &ExportControl, ) -> Result<(), ExportError>
table to out; text cells with cells, as a text format
does (a spreadsheet format reads ExportCell::value instead).impl Copy for CsvFormat
impl Eq for CsvFormat
impl StructuralPartialEq for CsvFormat
Auto Trait Implementations§
impl Freeze for CsvFormat
impl RefUnwindSafe for CsvFormat
impl Send for CsvFormat
impl Sync for CsvFormat
impl Unpin for CsvFormat
impl UnsafeUnpin for CsvFormat
impl UnwindSafe for CsvFormat
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> 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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§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 more§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().