Struct Reader

Source
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>

Source

pub fn new() -> Self

Constructs a new reader.

Source

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'-')
);
Source

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§

Source§

impl<const N: usize> Debug for Reader<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Default for Reader<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.