ng-postcode
Nigeria's National Digital Alphanumeric Postcode in Rust: offline parsing and validation, plus a client for the NIPOST API.
Unofficial. Not made or endorsed by NIPOST.
Offline
use ;
// Hyphens, spaces and case are all accepted.
let code: Postcode = "ek 01 a03 fk 01".parse?;
assert_eq!; // canonical
assert_eq!; // compact, for storage
assert_eq!; // for display
assert_eq!;
assert_eq!;
Postcode::parsechecks the structure: 2 letters, 2 digits, 3 letters or digits, 2 letters, 2 digits, with numeric segments from 01 to 99.Postcode::parse_lenientfirst swaps look-alike characters that cannot occur where they stand (O/0,I/1,S/5,B/8) and reports how many it changed.Postcode::from_segmentsassembles a code from its parts and zero-fills the LGA and unit.PostcodeisCopy, 11 bytes, and sorts by state, LGA, district, area, unit.
A well-formed code is not necessarily assigned to a building, and the state is not checked against a list of state codes. Only the API can confirm that a postcode exists.
API
= { = "0.1", = ["client"] }
use ;
let client = new;
let found = client.send?;
println!;
api covers lookup, autocomplete, reverse geocoding and nearby search. Each function returns a Request value and Request::decode turns a status and body into a typed result, so the api feature alone works with any HTTP client, sync or async. The client feature adds a small blocking one.
Features
| Feature | Adds |
|---|---|
serde |
Serialize and Deserialize for Postcode |
api |
Request and response types, no I/O |
client |
Blocking HTTP client |
License
MIT