typst/vendor/csv/examples/tutorial-read-serde-invalid-02.rs

31 lines
662 B
Rust
Raw Permalink Normal View History

2024-10-16 14:15:33 +03:00
#![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);
}
}