| Crates.io | us_address_parser |
| lib.rs | us_address_parser |
| version | 0.3.0 |
| created_at | 2024-09-11 16:42:03.660757+00 |
| updated_at | 2025-03-12 15:47:30.79664+00 |
| description | A Rust crate that parses U.S. street addresses. |
| homepage | https://github.com/Cosiamo/us_address_parser |
| repository | https://github.com/Cosiamo/us_address_parser |
| max_upload_size | |
| id | 1372080 |
| size | 42,015 |
A Rust Crate that parses United States street addresses.
To get started, simply import the AddressParsing trait to your file, and add the parse_addr() method to the String or &str you want to parse. It will return the Address struct, which contains; the street number, street name, street type, unit type, and unit number. Each of these fields are Option<String>.
use us_address_parser::AddressParsing;
fn main() {
let addresses: Vec<&str> = vec![
"123 Main Ave",
"456 Maple Blvd Apt 122",
"789 3rd St Lot B"
];
for addr in addresses {
println!("{}", &addr);
let address = addr.parse_addr();
println!("Street_no:{:?}, dir:{:?}, street_name:{:?}, street_type:{:?}, unit_type:{:?}, unit_no:{:?}\n==========",
address.street_no, address.direction, address.street_name,
address.street_type, address.unit_type, address.unit_no
);
}
}
123 Main Ave
Street_no:Some("123"), dir:None, street_name:Some("MAIN"), street_type:Some("AVE"), unit_type:None, unit_no:None
==========
456 Maple Blvd Apt 122
Street_no:Some("456"), dir:None, street_name:Some("MAPLE"), street_type:Some("BLVD"), unit_type:Some("APT"), unit_no:Some("122")
==========
789 3rd St Lot B
Street_no:Some("789"), dir:None, street_name:Some("3RD"), street_type:Some("ST"), unit_type:Some("LOT"), unit_no:Some("B")
==========
The [AddressParsing] trait is already implemented for strings,
struct CustomerInfo {
id: usize,
customer_name: String,
customer_address: String
}
impl AddressParsing for CustomerInfo {
fn parse_addr(&self) -> Address {
us_address_parser::string_to_address(self.customer_address)
}
}
The string_to_address() function does what it's name implies, converts a String to an Address.