Files
rk35xx-android14/external/rust/crates/csv/examples/tutorial-read-serde-02.rs
T
hmz007 36ed224bac Rockchip Anroid14_SDK 20240628-rkr5 (2556df1a)
Signed-off-by: hmz007 <hmz007@gmail.com>
Change-Id: Ib87fdbe7a0be7dc961af3500fe9ea4589a127f9f
2024-10-29 18:12:02 +08:00

25 lines
713 B
Rust

use std::{error::Error, io, process};
// This introduces a type alias so that we can conveniently reference our
// record type.
type Record = (String, String, Option<u64>, f64, f64);
fn run() -> Result<(), Box<dyn Error>> {
let mut rdr = csv::Reader::from_reader(io::stdin());
// Instead of creating an iterator with the `records` method, we create
// an iterator with the `deserialize` method.
for result in rdr.deserialize() {
// We must tell Serde what type we want to deserialize into.
let record: Record = result?;
println!("{:?}", record);
}
Ok(())
}
fn main() {
if let Err(err) = run() {
println!("{}", err);
process::exit(1);
}
}