Try to make the store representation smaller
This commit is contained in:
parent
68bedf2c36
commit
4ace40319f
|
@ -10,3 +10,4 @@ csv = "1.1.6"
|
|||
serde = { version = "1.0.145", features = ["derive"] }
|
||||
serde_repr = "0.1.9"
|
||||
extindex = "0.5.0"
|
||||
rust_decimal = "1.26.1"
|
||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -1,9 +1,11 @@
|
|||
use csv::ReaderBuilder;
|
||||
use extindex::{Builder, Entry, SerdeWrapper, Reader as ExtReader};
|
||||
use rust_decimal::Decimal;
|
||||
use std::error::Error;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
use std::str::FromStr;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde;
|
||||
use serde_repr::*;
|
||||
|
@ -74,20 +76,24 @@ struct SmolPostcode {
|
|||
usertype: UserType,
|
||||
positional_quality_indicator: PositionalQuality,
|
||||
country: String,
|
||||
latitude: Option<String>,
|
||||
longitude: Option<String>,
|
||||
latitude: Option<Decimal>,
|
||||
longitude: Option<Decimal>,
|
||||
}
|
||||
|
||||
impl SmolPostcode {
|
||||
fn from_postcode(full: Postcode) -> Self {
|
||||
let to_dec = |n: Option<String>| match n {
|
||||
Some(str) => Decimal::from_str(&str).ok(),
|
||||
None => None,
|
||||
};
|
||||
SmolPostcode {
|
||||
postcode: full.postcode.to_owned(),
|
||||
status: full.status,
|
||||
usertype: full.usertype,
|
||||
positional_quality_indicator: full.positional_quality_indicator.to_owned(),
|
||||
country: full.country.to_owned(),
|
||||
latitude: full.latitude.to_owned(),
|
||||
longitude: full.longitude.to_owned(),
|
||||
latitude: to_dec(full.latitude),
|
||||
longitude: to_dec(full.longitude),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,8 +105,10 @@ fn read() -> Result<(), Box<dyn Error>> {
|
|||
let mut i: u32 = 0;
|
||||
for result in rdr.deserialize() {
|
||||
let record: Postcode = result?;
|
||||
// println!("{}:: {:?}", i, record);
|
||||
println!("{}:: {:?}", i, &record);
|
||||
i += 1;
|
||||
let smol = SmolPostcode::from_postcode(record);
|
||||
println!("As smol: {:?}", smol);
|
||||
}
|
||||
println!("Read {:?} postcodes", i);
|
||||
Ok(())
|
||||
|
@ -127,10 +135,6 @@ fn csv_iter(file: impl io::Read + 'static) -> impl Iterator<Item=String> {
|
|||
|
||||
fn main() {
|
||||
build();
|
||||
if let Err(err) = read() {
|
||||
println!("error running example: {}", err);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue