Formatter

Struct Formatter 

Source
pub struct Formatter { /* private fields */ }
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§

Source§

impl Formatter

Source

pub fn format(&self, into_addr: impl Into<Place>) -> Result<String, Error>

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()
   )
Source

pub fn format_with_config( &self, into_addr: impl Into<Place>, conf: Configuration, ) -> Result<String, Error>

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

Source

pub fn short_addr_format( &self, into_addr: impl Into<Place>, ) -> Result<String, Error>

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()
   )
Source

pub fn short_addr_format_with_config( &self, into_addr: impl Into<Place>, conf: Configuration, ) -> Result<String, Error>

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§

Source§

impl Default for Formatter

Source§

fn default() -> Self

Default constructor

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.