1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//! CSV serialization and deserialization for `no_std` crates.
//!
//! `serde-csv-core` builds upon [`csv-core`](https://crates.io/crates/csv-core) crate.
//! It doesn't require any memory allocations, which means that it's well-suited for embedded environments.
//!
//! # Serialization
//! [`Writer`] serializes one record at a time.
//! ```
//! use heapless::String;
//! use serde::Serialize;
//!
//! #[derive(Serialize)]
//! struct Record {
//! pub country: String<32>,
//! pub city: String<32>,
//! pub population: u32,
//! }
//!
//! let records = [
//! Record {
//! country: "Poland".into(),
//! city: "Cracow".into(),
//! population: 766_683,
//! },
//! Record {
//! country: "Japan".into(),
//! city: "Tokyo".into(),
//! population: 13_515_271,
//! },
//! ];
//!
//! let mut writer = serde_csv_core::Writer::new();
//! let mut csv = [0; 128];
//! let mut nwritten = 0;
//! for record in &records {
//! nwritten += writer.serialize(&record, &mut csv[nwritten..])?;
//! }
//!
//! assert_eq!(&csv[..nwritten], b"Poland,Cracow,766683\nJapan,Tokyo,13515271\n");
//!
//! # Ok::<(), serde_csv_core::ser::Error>(())
//! ```
//!
//! # Deserialization
//! [`Reader<N>`] deserializes one record at a time.
//! `N` is a capacity of an internal buffer that's used to temporarily store unescaped fields.
//! ```
//! use heapless::{String, Vec};
//! use serde::Deserialize;
//!
//! #[derive(Debug, PartialEq, Eq, Deserialize)]
//! struct Record {
//! pub country: String<32>,
//! pub city: String<32>,
//! pub population: u32,
//! }
//!
//! let csv = b"Poland,Cracow,766683\nJapan,Tokyo,13515271\n";
//!
//! let mut reader = serde_csv_core::Reader::<32>::new();
//! let mut records: Vec<Record, 2> = Vec::new();
//! let mut nread = 0;
//! while nread < csv.len() {
//! let (record, n) = reader.deserialize::<Record>(&csv[nread..])?;
//! nread += n;
//! records.push(record);
//! }
//!
//! assert_eq!(records, &[
//! Record {
//! country: "Poland".into(),
//! city: "Cracow".into(),
//! population: 766_683,
//! },
//! Record {
//! country: "Japan".into(),
//! city: "Tokyo".into(),
//! population: 13_515_271,
//! },
//! ]);
//! # Ok::<(), serde_csv_core::de::Error>(())
//! ```
//!
//! # Configuration
//! Both [`Writer`] and [`Reader`] are wrappers for [`csv_core::Writer`]
//! and [`csv_core::Reader`], respectively. You can use [`csv_core::WriterBuilder`]
//! and [`csv_core::ReaderBuilder`] in combination with `from_builder` constructors
//! to tweak things like field delimiters etc.
//! ```
//! use serde_csv_core::csv_core;
//!
//! let writer = serde_csv_core::Writer::from_builder(
//! csv_core::WriterBuilder::new()
//! .delimiter(b'-')
//! );
//! ```
pub use Reader;
pub use Writer;
pub use csv_core;
pub use heapless;