Split in too, added a lookup cli

This commit is contained in:
Alex Wright 2022-10-10 00:58:53 +01:00
parent f2d5150cc3
commit 17d7140393
3 changed files with 27 additions and 2 deletions

View File

@ -11,3 +11,12 @@ 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 = { version = "1.26.1", features = ["serde-str"] } rust_decimal = { version = "1.26.1", features = ["serde-str"] }
pico-args = "0.5.0"
[[bin]]
name = "index"
path = "src/index.rs"
[[bin]]
name = "lookup"
path = "src/lookup.rs"

View File

@ -82,7 +82,7 @@ struct Postcode {
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
struct SmolPostcode { pub struct SmolPostcode {
postcode: String, postcode: String,
usertype: UserType, usertype: UserType,
positional_quality_indicator: PositionalQuality, positional_quality_indicator: PositionalQuality,

16
src/lookup.rs Normal file
View File

@ -0,0 +1,16 @@
use extindex::{Builder, Entry, SerdeWrapper, Reader as ExtReader};
use std::path::Path;
mod index;
use crate::index::SmolPostcode;
fn main() {
let mut pargs = pico_args::Arguments::from_env();
let lookup: String = pargs.free_from_str().unwrap();
println!("Searching for {}", &lookup);
let index_file_path = Path::new("./postcodes.db");
let reader = ExtReader::<String, SerdeWrapper<SmolPostcode>>::open(index_file_path).unwrap();
let here = reader.find(&lookup).unwrap().expect("Not found");
println!("Here: {:?}", here.value().0);
}