Struct rustpostal::expand::NormalizeOptions [−][src]
pub struct NormalizeOptions { /* fields omitted */ }
Expand description
Normalization options.
Options are required to expand a postal address to its normalized variations. They are created by defining optionally language-codes for normalization (e.g. ‘en’), and then gradually adding more options.
A expand
method is implemented to use the options for normalizing an address.
Examples
use std::ffi::NulError; use rustpostal::expand::{AddressComponents, StringOptions, NormalizeOptions}; fn main() -> Result<(), NulError> { let languages = ["en", "gb"]; let mut options = NormalizeOptions::new(Some(languages.iter()))?; assert_eq!(options.languages().unwrap().collect::<Vec<&str>>(), Vec::from(languages)); let s_options = StringOptions::TRANSLITERATE | StringOptions::LOWERCASE; let components = AddressComponents::NAME | AddressComponents::LEVEL; options.add_string_option(s_options); assert!(options.string_options().as_ref().unwrap().contains(s_options)); options.add_address_component(components); assert!(options.address_components().as_ref().unwrap().contains(components)); Ok(()) }
Implementations
Create new instance with default options.
languages
override the respective option field, if given.
Add string option.
Add address component option.
Return current languages.
Examples
use std::ffi::NulError; use rustpostal::expand::NormalizeOptions; fn main() -> Result<(), NulError> { let options = NormalizeOptions::default(); assert!(options.languages().is_none()); let languages = ["en", "gb"]; let options = NormalizeOptions::new(Some(languages.iter()))?; assert_eq!(options.languages().unwrap().collect::<Vec<&str>>(), Vec::from(languages)); Ok(()) }
Return current address components.
use rustpostal::expand::{NormalizeOptions, AddressComponents}; let mut options = NormalizeOptions::default(); assert_eq!(options.address_components(), None); options.add_address_component(AddressComponents::NAME); assert_eq!(options.address_components(), Some(&AddressComponents::NAME));
Return current string options.
use rustpostal::expand::{NormalizeOptions, StringOptions}; let mut options = NormalizeOptions::default(); assert_eq!(options.string_options(), None); options.add_string_option(StringOptions::TRANSLITERATE); assert_eq!(options.string_options(), Some(&StringOptions::TRANSLITERATE));
Expand address into normalized variations using libpostal.
Examples
use std::ffi::NulError; use rustpostal::LibModules; use rustpostal::expand::NormalizeOptions; use rustpostal::error::RuntimeError; fn main() -> Result<(), RuntimeError> { let postal_module = LibModules::Expand; postal_module.setup()?; let mut options = NormalizeOptions::default(); let address = "St Johns Centre, Rope Walk, Bedford, Bedfordshire, MK42 0XE, United Kingdom"; let expanded = options.expand(address)?; for variation in &expanded { assert!(variation.ends_with("kingdom")) } Ok(()) }
Errors
The method will return an error if the supplied address
contains an internal null byte. The error is represented by
NulError
.
Trait Implementations
Returns the “default value” for a type. Read more
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for NormalizeOptions
impl Send for NormalizeOptions
impl Sync for NormalizeOptions
impl Unpin for NormalizeOptions
impl UnwindSafe for NormalizeOptions
Blanket Implementations
Mutably borrows from an owned value. Read more