Split in too, added a lookup cli
This commit is contained in:
parent
f2d5150cc3
commit
17d7140393
|
@ -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"
|
||||||
|
|
|
@ -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,
|
||||||
|
@ -117,7 +117,7 @@ fn main() {
|
||||||
.filter(|full| match full.status { Status::Live => true, _ => false })
|
.filter(|full| match full.status { Status::Live => true, _ => false })
|
||||||
.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 index_file_path = Path::new("./postcodes.db");
|
||||||
let builder: Builder<String, SerdeWrapper<SmolPostcode>> = Builder::new(index_file_path);
|
let builder: Builder<String, SerdeWrapper<SmolPostcode>> = Builder::new(index_file_path);
|
||||||
builder.build(entries.into_iter()).unwrap();
|
builder.build(entries.into_iter()).unwrap();
|
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue