typst/vendor/csv/examples/tutorial-read-serde-invalid-02.rs
2024-10-16 14:18:46 +03:00

31 lines
662 B
Rust

#![allow(dead_code)]
use std::{error::Error, io, process};
use serde::Deserialize;
#[derive(Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
struct Record {
latitude: f64,
longitude: f64,
#[serde(deserialize_with = "csv::invalid_option")]
population: Option<u64>,
city: String,
state: String,
}
fn run() -> Result<(), Box<dyn Error>> {
let mut rdr = csv::Reader::from_reader(io::stdin());
for result in rdr.deserialize() {
let record: Record = result?;
println!("{:?}", record);
}
Ok(())
}
fn main() {
if let Err(err) = run() {
println!("{}", err);
process::exit(1);
}
}