csv::record
On this page
Record: one row's fields as views of the text it was read from,
and Headers, the header's names with a lookup by name.
Structs
RecordSource
pub struct RecordOne record. A field is a view of the text the reader holds, not a
copy; only a quoted field with an escaped quote ("") is rebuilt,
when it is asked for.
let r = csv::Dialect::new().from_str("name,qty\n\"Smith, J\",3\n");
let rec = try! r.next() ?? csv::Record::new();
assert(rec.len() == 2 && rec[0] == "Smith, J" && rec.is_quoted(0));
assert(rec.get(5) is none);
assert(rec.line() == 2);
An empty record, to read into with
Reader::read.nabiassert(csv::Record::new().is_empty());A record holding
fields, for writing or tests.nabilet rec = csv::Record::from_list(["a", "b,c"]); assert(rec.len() == 2 && rec[1] == "b,c");The number of fields.
nabiassert(csv::Record::from_list(["x", "y"]).len() == 2);Whether there are no fields.
nabiassert(!csv::Record::from_list([""]).is_empty());Field
i, ornonepast the last.nabilet rec = csv::Record::from_list(["x"]); assert(rec.get(0) == "x" && rec.get(1) is none);Whether field
iwas quoted in the input. A quoted empty field ("") is a value where an unquoted one may stand for a missing one.nabilet rec = try! csv::Dialect::new().has_header(false).from_str("\"\",\n").next() ?? csv::Record::new(); assert(rec.is_quoted(0) && !rec.is_quoted(1));The line the record starts on, 1-based (0 for a record not read).
nabilet r = csv::Dialect::new().from_str("a\n\"x\ny\"\nz\n"); _ = try! r.next(); assert((try! r.next() ?? csv::Record::new()).line() == 4);The byte offset of the record in the input.
nabilet r = csv::Dialect::new().from_str("a\n12\n"); assert((try! r.next() ?? csv::Record::new()).position() == 2);The field named
nameinh, ornone.nabilet r = csv::Dialect::new().from_str("id,name\n7,ann\n"); let h = try! r.headers(); let rec = try! r.next() ?? csv::Record::new(); assert(rec.by_name(h, "name") == "ann" && rec.by_name(h, "age") is none);The fields in order.
nabilet rec = csv::Record::from_list(["a", "b"]); assert(rec.iter().collect::<List<str>>() == ["a", "b"]);The fields as a list.
nabiassert(csv::Record::from_list(["a", "b"]).to_list() == ["a", "b"]);Remove every field, keeping the room.
nabilet rec = csv::Record::from_list(["a"]); rec.clear(); assert(rec.is_empty());
Trait implementations 5
impl Index<usize> for Recordimpl Clone for Recordimpl PartialEq for Recordimpl Display for Recordimpl Debug for Record
FieldsSource
pub struct FieldsThe fields of a Record, in order.
let n = 0;
for f in csv::Record::from_list(["a", "b"]).iter() { n += f.len(); }
assert(n == 2);
Trait implementations 1
impl Iterator for Fields
HeadersSource
pub struct HeadersThe header's names, with a lookup by name.
let r = csv::Dialect::new().from_str("id,name,id\n");
let h = try! r.headers();
assert(h.len() == 3 && h.index("name") == 1usize);
assert(h.index("id") == 0usize && h.index("x") is none);
Headers with these names.
nabiassert(csv::Headers::new(["a", "b"]).names() == ["a", "b"]);The names, in order.
nabiassert(csv::Headers::new(["x"]).names() == ["x"]);The number of names.
nabiassert(csv::Headers::new(["x", "y"]).len() == 2);Whether there are none (no header was read).
nabiassert(csv::Headers::new([]).is_empty());The position of the first name
name, ornone.nabiassert(csv::Headers::new(["a", "b"]).index("b") == 1usize);Name
i, ornone.nabiassert(csv::Headers::new(["a"]).get(0) == "a");