Crates.io | justcsv |
lib.rs | justcsv |
version | 0.1.2 |
source | src |
created_at | 2024-06-24 13:48:48.54824 |
updated_at | 2024-08-29 12:47:58.544685 |
description | Simple CSV-file reader/writer |
homepage | https://github.com/akmitrich/justcsv |
repository | https://github.com/akmitrich/justcsv |
max_upload_size | |
id | 1282258 |
size | 26,237 |
Inspired by csv_simple
crate.
Conforms the RFC 4180. Please be aware of that RFC. According to RFC CSV-file is ASCII-only, this crate treats CSV-files as UTF-8.
impl<R: BufRead> reader::CsvReader<R> {
pub fn new(reader: R) -> Self {...}
pub fn with_config(source: R, config: Config) -> Self {...}
pub fn headers(&self) -> Option<&[String]> {...}
}
impl<R: BufRead> Iterator for reader::CsvReader<R> {
type Item = crate::Result<Box<[String]>>;
...
}
struct Config {
pub has_headers: bool,
pub separator: char,
pub escape: char,
}
Config struct exported as CsvReaderConfig
in lib.rs
implements builder pattern and Default trait.
CsvReader::headers(...)
returns Some
if config.has_headers == true
and parsing first record was successful. If you passed config.has_headers == true
but get None
from CsvReader::headers(...)
means parsing first record failed. Note that iterating through such a reader is undefined behaviour.
Is not as convinient as Reader API. It just helps you to escape special characters while writing to the dest
.
Headers have no special treatment, they are just another row. Only if you try to write them after records you get an error.
impl<W: Write> CsvWriter<W> {
pub fn new(dest: W) -> Self {...}
pub fn with_config(dest: W, config: CsvWriterConfig) -> Self {...}
pub fn write_row(&mut self, row: &[impl AsRef<str>]) -> crate::Result<()> {...}
pub fn headers(&mut self, headers: &[impl AsRef<str>]) -> crate::Result<()> {...}
pub fn write_doc(&mut self, doc: &[&[impl AsRef<str>]]) -> crate::Result<()> {...}
}
// as CsvWriterConfig
pub struct Config {
pub separator: char,
pub escape: char,
pub newline: NewLine,
}
pub enum NewLine {
Rfc,
Unix,
Custom(String),
}
Config struct exported as CsvWriterConfig
in lib.rs
implements builder pattern and Default trait.
Due to nom the crate has MIT License.