csv::error
CsvError: what went wrong, where (line and column, 1-based), and
what to write instead.
Structs
CsvErrorSource
pub struct CsvErrorA CSV read, decode or write error.
let r = csv::Dialect::new().has_header(false).from_str("a,\"b\n");
let got = try r.next() catch e {
assert(e.kind == csv::ErrorKind::UnclosedQuote && e.line == 1 && e.column == 3);
assert(f"{e}".starts_with("line 1, column 3: "));
return;
};
panic(f"read {got:?}");
What went wrong.
The line, 1-based; 0 when there is none.
The column in characters, 1-based; 0 when there is none.
The field's name (or its number when there is no header), for a decode error; else empty.
The message: what is wrong and what to write instead.
An error without a position.
nabilet e = csv::CsvError::new(csv::ErrorKind::Decode, "`x` is not a number"); assert(f"{e}" == "`x` is not a number");The same error at
line,column.nabilet e = csv::CsvError::new(csv::ErrorKind::Decode, "bad").at(3, 0); assert(f"{e}" == "line 3: bad");The message with its position, as
Displaywrites it.nabilet e = csv::CsvError::new(csv::ErrorKind::Io, "disk full"); assert(e.message() == "disk full");
Trait implementations 3
impl Display for CsvErrorimpl Debug for CsvErrorimpl Error for CsvError
Enums
ErrorKindSource
pub enum ErrorKindThe kind of a CsvError.
let r = csv::from_str("a,b\n1\n");
let n = try r.count() catch e {
assert(e.kind == csv::ErrorKind::FieldCount);
return;
};
panic(f"read {n}");
Reading or writing the stream failed.
The input is not UTF-8.
A quoted field has no closing quote.
Text follows a closing quote before the delimiter.
A record has another field count than the first.
A field does not convert to the type asked for.
The writer cannot write a field as asked.