packages

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 Record

One 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.

nabi
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);
  • pub fn new() -> Record§

    Source

    An empty record, to read into with Reader::read.

    nabi
    assert(csv::Record::new().is_empty());
    
  • pub fn from_list(fields: List<str>) -> Record§

    Source

    A record holding fields, for writing or tests.

    nabi
    let rec = csv::Record::from_list(["a", "b,c"]);
    assert(rec.len() == 2 && rec[1] == "b,c");
    
  • pub fn len(self) -> usize§

    Source

    The number of fields.

    nabi
    assert(csv::Record::from_list(["x", "y"]).len() == 2);
    
  • pub fn is_empty(self) -> bool§

    Source

    Whether there are no fields.

    nabi
    assert(!csv::Record::from_list([""]).is_empty());
    
  • pub fn get(self, i: usize) -> str | none§

    Source

    Field i, or none past the last.

    nabi
    let rec = csv::Record::from_list(["x"]);
    assert(rec.get(0) == "x" && rec.get(1) is none);
    
  • pub fn is_quoted(self, i: usize) -> bool§

    Source

    Whether field i was quoted in the input. A quoted empty field ("") is a value where an unquoted one may stand for a missing one.

    nabi
    let rec = try! csv::Dialect::new().has_header(false).from_str("\"\",\n").next() ?? csv::Record::new();
    assert(rec.is_quoted(0) && !rec.is_quoted(1));
    
  • pub fn line(self) -> usize§

    Source

    The line the record starts on, 1-based (0 for a record not read).

    nabi
    let r = csv::Dialect::new().from_str("a\n\"x\ny\"\nz\n");
    _ = try! r.next();
    assert((try! r.next() ?? csv::Record::new()).line() == 4);
    
  • pub fn position(self) -> u64§

    Source

    The byte offset of the record in the input.

    nabi
    let r = csv::Dialect::new().from_str("a\n12\n");
    assert((try! r.next() ?? csv::Record::new()).position() == 2);
    
  • pub fn by_name(self, h: Headers, name: str) -> str | none§

    Source

    The field named name in h, or none.

    nabi
    let 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);
    
  • pub fn iter(self) -> Fields§

    Source

    The fields in order.

    nabi
    let rec = csv::Record::from_list(["a", "b"]);
    assert(rec.iter().collect::<List<str>>() == ["a", "b"]);
    
  • pub fn to_list(self) -> List<str>§

    Source

    The fields as a list.

    nabi
    assert(csv::Record::from_list(["a", "b"]).to_list() == ["a", "b"]);
    
  • pub fn clear(ref self)§

    Source

    Remove every field, keeping the room.

    nabi
    let rec = csv::Record::from_list(["a"]);
    rec.clear();
    assert(rec.is_empty());
    
Trait implementations 5
  • impl Index<usize> for Record
  • impl Clone for Record
  • impl PartialEq for Record
  • impl Display for Record
  • impl Debug for Record

FieldsSource

pub struct Fields

The fields of a Record, in order.

nabi
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 Headers

The header's names, with a lookup by name.

nabi
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);
  • pub fn new(names: List<str>) -> Headers§

    Source

    Headers with these names.

    nabi
    assert(csv::Headers::new(["a", "b"]).names() == ["a", "b"]);
    
  • pub fn names(self) -> List<str>§

    Source

    The names, in order.

    nabi
    assert(csv::Headers::new(["x"]).names() == ["x"]);
    
  • pub fn len(self) -> usize§

    Source

    The number of names.

    nabi
    assert(csv::Headers::new(["x", "y"]).len() == 2);
    
  • pub fn is_empty(self) -> bool§

    Source

    Whether there are none (no header was read).

    nabi
    assert(csv::Headers::new([]).is_empty());
    
  • pub fn index(self, name: str) -> usize | none§

    Source

    The position of the first name name, or none.

    nabi
    assert(csv::Headers::new(["a", "b"]).index("b") == 1usize);
    
  • pub fn get(self, i: usize) -> str | none§

    Source

    Name i, or none.

    nabi
    assert(csv::Headers::new(["a"]).get(0) == "a");