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