Delete debug/dev code and tidy up

This commit is contained in:
Alex Wright 2022-10-10 00:20:49 +01:00
parent b27b38014e
commit f2d5150cc3
1 changed files with 3 additions and 52 deletions

View File

@ -1,7 +1,6 @@
use csv::ReaderBuilder; use csv::ReaderBuilder;
use extindex::{Builder, Entry, SerdeWrapper, Reader as ExtReader}; use extindex::{Builder, Entry, SerdeWrapper};
use rust_decimal::Decimal; use rust_decimal::Decimal;
use std::error::Error;
use std::io; use std::io;
use std::path::Path; use std::path::Path;
use std::str::FromStr; use std::str::FromStr;
@ -85,7 +84,6 @@ struct Postcode {
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
struct SmolPostcode { struct SmolPostcode {
postcode: String, postcode: String,
status: Status,
usertype: UserType, usertype: UserType,
positional_quality_indicator: PositionalQuality, positional_quality_indicator: PositionalQuality,
country: Country, country: Country,
@ -101,7 +99,6 @@ impl SmolPostcode {
}; };
SmolPostcode { SmolPostcode {
postcode: full.postcode.to_owned(), postcode: full.postcode.to_owned(),
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(),
@ -111,51 +108,7 @@ impl SmolPostcode {
} }
} }
fn read() -> Result<(), Box<dyn Error>> {
let mut rdr = ReaderBuilder::new()
.has_headers(false)
.from_reader(io::stdin());
let mut i: u32 = 0;
for result in rdr.deserialize() {
let record: Postcode = result?;
println!("{}:: {:?}", i, &record);
i += 1;
let smol = SmolPostcode::from_postcode(record);
println!("As smol: {:?}", smol);
}
println!("Read {:?} postcodes", i);
Ok(())
}
/*
* Thought this would be easy..
*
let postcodes = csv_iter(io::stdin());
for p in postcodes.take(10) {
println!("Postcode: {}", p);
}
fn csv_iter(file: impl io::Read + 'static) -> impl Iterator<Item=String> {
let mut reader = ReaderBuilder::new()
.has_headers(false)
.from_reader(file);
let iter = reader.deserialize();
iter
.filter_map(|r: Result<Postcode, csv::Error>| r.ok())
.map(|postcode| postcode.postcode.to_owned())
.collect()
}
*/
fn main() { fn main() {
build();
}
fn build() {
let index_file_path = Path::new("./postcodes.db");
let builder: Builder<String, SerdeWrapper<SmolPostcode>> = Builder::new(index_file_path);
let mut csv_reader = ReaderBuilder::new() let mut csv_reader = ReaderBuilder::new()
.has_headers(false) .has_headers(false)
.from_reader(io::stdin()); .from_reader(io::stdin());
@ -165,9 +118,7 @@ fn build() {
.map(|full: Postcode| SmolPostcode::from_postcode(full)) .map(|full: Postcode| SmolPostcode::from_postcode(full))
.map(|smol| Entry::new(smol.postcode.to_owned(), SerdeWrapper(smol))); .map(|smol| Entry::new(smol.postcode.to_owned(), SerdeWrapper(smol)));
let index_file_path = Path::new("./postcodes.db");
let builder: Builder<String, SerdeWrapper<SmolPostcode>> = Builder::new(index_file_path);
builder.build(entries.into_iter()).unwrap(); builder.build(entries.into_iter()).unwrap();
let reader = ExtReader::<String, SerdeWrapper<SmolPostcode>>::open(index_file_path).unwrap();
let here = reader.find(&"LS27 8BW".to_string()).unwrap().expect("Not found");
println!("Here: {:?}", here.value().0);
} }