pub struct Row { /* private fields */ }Implementations§
Source§impl Row
impl Row
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of fields parsed for this row.
Fields are still counted when the row carries an error.
pub fn is_empty(&self) -> bool
Source§impl Row
impl Row
Sourcepub fn deserialize<T>(&self) -> Result<T, ReadError>where
T: DeserializeOwned,
pub fn deserialize<T>(&self) -> Result<T, ReadError>where
T: DeserializeOwned,
Deserialize this row into a T.
Headers must have been set on the parent Reader
via parse_headers or
set_headers before calling this method.
Struct fields are matched by column name.
A struct field with no matching column deserializes from an empty string. A field whose column exists but is absent from this row (short or ragged row), or whose bytes are not valid UTF-8, is reported as an error rather than being silently turned into an empty string.
§Errors
Returns ReadError with kind Deserialize
if headers have not been set, if the headers contain duplicate names
(which makes name-based lookup ambiguous), or if deserialization fails
(type mismatch, unknown field, missing column data, invalid UTF-8, etc.).
§Example
use csv::Reader;
use serde::Deserialize;
#[derive(Deserialize)]
struct Record { name: String, age: u32 }
let mut reader = Reader::new(std::io::Cursor::new(b"name,age\nAlice,30\n"));
reader.parse_headers()?;
for row in reader.rows() {
let rec: Record = row.deserialize()?;
println!("{} is {}", rec.name, rec.age);
}