pub struct Reader<const N: usize> { /* private fields */ }
Expand description
Wrapper for csv_core::Reader
that provides methods for deserialization using serde
.
N
is a capacity of an internal buffer that’s used to temporarily store unescaped fields.
Implementations§
Source§impl<const N: usize> Reader<N>
impl<const N: usize> Reader<N>
Sourcepub fn from_builder(builder: impl Borrow<ReaderBuilder>) -> Self
pub fn from_builder(builder: impl Borrow<ReaderBuilder>) -> Self
Constructs a new reader from csv_core::ReaderBuilder
.
§Example
use serde_csv_core::csv_core;
let reader = serde_csv_core::Reader::<16>::from_builder(
csv_core::ReaderBuilder::new()
.delimiter(b'-')
);
Sourcepub fn deserialize<'de, T>(&mut self, input: &[u8]) -> Result<(T, usize)>where
T: Deserialize<'de>,
pub fn deserialize<'de, T>(&mut self, input: &[u8]) -> Result<(T, usize)>where
T: Deserialize<'de>,
Deserializes a given CSV byte slice into a value of type T
.
The second element of the resulting tuple is a number of bytes read.
§Example
use heapless::String;
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\n";
let mut reader = serde_csv_core::Reader::<32>::new();
let (record, nread) = reader.deserialize::<Record>(&csv[..])?;
assert_eq!(record, Record {
country: "Poland".into(),
city: "Cracow".into(),
population: 766_683,
});
assert_eq!(nread, 21);
Trait Implementations§
Auto Trait Implementations§
impl<const N: usize> Freeze for Reader<N>
impl<const N: usize> RefUnwindSafe for Reader<N>
impl<const N: usize> Send for Reader<N>
impl<const N: usize> Sync for Reader<N>
impl<const N: usize> Unpin for Reader<N>
impl<const N: usize> UnwindSafe for Reader<N>
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
Mutably borrows from an owned value. Read more