Struct address_formatter::Formatter[][src]

pub struct Formatter { /* fields omitted */ }
Expand description

This Formatter holds all the configuration needed to format a Place to a nice text.

The main method is the format method, that takes a Place or something that can be converted to a Place and return a result with the formatted String

   use address_formatter::Component::*;
   let formatter = address_formatter::Formatter::default();

   let addr: address_formatter::Place = hashmap!(
       City => "Toulouse",
       Country => "France",
       CountryCode => "FR",
       County => "Toulouse",
       HouseNumber => "17",
       Neighbourhood => "Lafourguette",
       Postcode => "31000",
       Road => "Rue du Médecin-Colonel Calbairac",
       State => "Midi-Pyrénées",
       Suburb => "Toulouse Ouest",
   ).into();

   assert_eq!(
       formatter.format(addr).unwrap(),
       r#"17 Rue du Médecin-Colonel Calbairac
31000 Toulouse
France
"#
       .to_owned()
   )

Implementations

make a human readable text from a Place

   use address_formatter::Component::*;
   let formatter = address_formatter::Formatter::default();

   let addr: address_formatter::Place = hashmap!(
       City => "Toulouse",
       Country => "France",
       CountryCode => "FR",
       County => "Toulouse",
       HouseNumber => "17",
       Neighbourhood => "Lafourguette",
       Postcode => "31000",
       Road => "Rue du Médecin-Colonel Calbairac",
       State => "Midi-Pyrénées",
       Suburb => "Toulouse Ouest",
   ).into();

   assert_eq!(
       formatter.format(addr).unwrap(),
       r#"17 Rue du Médecin-Colonel Calbairac
31000 Toulouse
France
"#
       .to_owned()
   )

make a human readable text from a Place Same as the format method, but with a Configuration object

make a human readable short text on 1 line with only the address Place There is basically only the housenumber and the road

   use address_formatter::Component::*;
   let formatter = address_formatter::Formatter::default();

   let addr: address_formatter::Place = hashmap!(
       City => "Toulouse",
       Country => "France",
       CountryCode => "FR",
       County => "Toulouse",
       HouseNumber => "17",
       Neighbourhood => "Lafourguette",
       Postcode => "31000",
       Road => "Rue du Médecin-Colonel Calbairac",
       State => "Midi-Pyrénées",
       Suburb => "Toulouse Ouest",
   ).into();

   assert_eq!(
       formatter.short_addr_format(addr).unwrap(),
       r#"17 Rue du Médecin-Colonel Calbairac"#
       .to_owned()
   )

make a human readable short text on 1 line with only the address Place Same as the short_addr_format method, but with a Configuration object

Trait Implementations

Default constructor

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.