expression

ByteRecord for non-UTF-8 fields

A ByteRecord preserves raw field bytes when input encoding is unknown. String records require valid UTF-8; decoding other encodings needs an explicit policy. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): 255 true Common mistake: Assuming a byte record automatically converts a legacy encoding to UTF-8.

Formal Syntax & Structure

rust syntaxrust
reader.byte_records(); reader.records()

Working Example

Example Snippetrust
fn main() {    let input = &b"label\n\xff\n"[..];    let mut bytes = csv::Reader::from_reader(input);    let row = bytes.byte_records().next().unwrap().unwrap();    println!("{}", row[0][0]);    let mut text = csv::Reader::from_reader(input);    println!("{}", text.records().next().unwrap().is_err());}
Rust Reference