From f2d5150cc3f743d80381b724d87fa3260f1d61c7 Mon Sep 17 00:00:00 2001 From: Alex Wright Date: Mon, 10 Oct 2022 00:20:49 +0100 Subject: [PATCH] Delete debug/dev code and tidy up --- src/main.rs | 55 +++-------------------------------------------------- 1 file changed, 3 insertions(+), 52 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2c2b080..246ac62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,6 @@ use csv::ReaderBuilder; -use extindex::{Builder, Entry, SerdeWrapper, Reader as ExtReader}; +use extindex::{Builder, Entry, SerdeWrapper}; use rust_decimal::Decimal; -use std::error::Error; use std::io; use std::path::Path; use std::str::FromStr; @@ -85,7 +84,6 @@ struct Postcode { #[derive(Serialize, Deserialize, Debug)] struct SmolPostcode { postcode: String, - status: Status, usertype: UserType, positional_quality_indicator: PositionalQuality, country: Country, @@ -101,7 +99,6 @@ impl SmolPostcode { }; 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(), @@ -111,51 +108,7 @@ impl SmolPostcode { } } -fn read() -> Result<(), Box> { - 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 { - let mut reader = ReaderBuilder::new() - .has_headers(false) - .from_reader(file); - let iter = reader.deserialize(); - iter - .filter_map(|r: Result| r.ok()) - .map(|postcode| postcode.postcode.to_owned()) - .collect() -} - */ - fn main() { - build(); -} - - -fn build() { - let index_file_path = Path::new("./postcodes.db"); - - let builder: Builder> = Builder::new(index_file_path); - let mut csv_reader = ReaderBuilder::new() .has_headers(false) .from_reader(io::stdin()); @@ -165,9 +118,7 @@ fn build() { .map(|full: Postcode| SmolPostcode::from_postcode(full)) .map(|smol| Entry::new(smol.postcode.to_owned(), SerdeWrapper(smol))); + let index_file_path = Path::new("./postcodes.db"); + let builder: Builder> = Builder::new(index_file_path); builder.build(entries.into_iter()).unwrap(); - - let reader = ExtReader::>::open(index_file_path).unwrap(); - let here = reader.find(&"LS27 8BW".to_string()).unwrap().expect("Not found"); - println!("Here: {:?}", here.value().0); }