All of the from_str() alias match arms except for the United States
use the alias stripped of any spaces, so you can pass in your country
name like, for example:
let input = "Great Britain";
let country = Country::from_str(input.replace(" ", "").as_str()).unwrap();
However, the "united states" alias added in #1 breaks expectations
since it contains a space, while no other country aliases contain
spaces, and so requires doing something weird for the above example
like:
let input = "United States";
let country_input = match input.to_lowercase().as_str() {
"united states" => input,
_ => input.replace(" ", "")
};
let country = Country::from_str(country_input.as_str()).unwrap();
This PR adds a new "unitedstates" alias to bring the US in line with
the rest of the countries in the from_str implementation. The
existing "united states" alias is not removed to avoid breaking
backwards compatibility.
I also updated the docs a little bit to make it more obvious that users
should strip spaces out of the input before passing to the various
methods, both by stating it explicitly and by including examples like
"UnitedStates" in the from_str() doctests, which have also been
slightly updated to perform assertions in addition to assigning values.
All of the
from_str()
alias match arms except for the United States use the alias stripped of any spaces, so you can pass in your country name like, for example:However, the
"united states"
alias added in #1 breaks expectations since it contains a space, while no other country aliases contain spaces, and so requires doing something weird for the above example like:This PR adds a new
"unitedstates"
alias to bring the US in line with the rest of the countries in thefrom_str
implementation. The existing"united states"
alias is not removed to avoid breaking backwards compatibility.I also updated the docs a little bit to make it more obvious that users should strip spaces out of the input before passing to the various methods, both by stating it explicitly and by including examples like
"UnitedStates"
in thefrom_str()
doctests, which have also been slightly updated to perform assertions in addition to assigning values.