Added Country enum.

[?]
Apr 9, 2021, 11:40 AM
GUXZCEWWPBCHXO26JVWZ74CTSDFDDO775YR7FKY7UGVZCA7GCSYAC

Dependencies

Change contents

  • file addition: main.rs (-xw-xw-x--)
    [2.6]
    use ui_data::countries::Country;
    use ui_data::{
    unemployment_series,
    unemployment_data,
    };
    pub fn main() {
    // unemployment_series(Country::Slovenia);
    // unemployment_data("LFHU24TTSIM647S");
    let s = unemployment_data("LRUNTTTTSIQ156S");
    println!("{}", s);
    }
  • replacement in src/lib.rs at line 1
    [2.16][2.17:104]()
    #[cfg(test)]
    mod tests {
    #[test]
    fn it_works() {
    assert_eq!(2 + 2, 4);
    [2.16]
    [2.104]
    //! Collect unemployment rate, inflation rate and interest rate server side.
    //!
    //! This crate contains concrete, country specific, functions for handling data.
    pub mod countries;
    use fred_api::Fred;
    use crate::countries::Country;
    /// Return a printed list of unemployment series for a particular country.
    /// ```
    /// unemployment_series(Country::Slovenia);
    /// ```
    pub fn unemployment_series(country: Country) {
    let tags = Fred::tags_series(&format!(
    "unemployment;{}",
    country,
    ));
    let seriess = tags.seriess;
    seriess
    .iter()
    .filter(|s| s.frequency == "Monthly" || s.frequency == "Quarterly")
    .filter(|s| s.seasonal_adjustment == "Seasonally Adjusted")
    .filter(|s| !s.title.contains("Male"))
    .filter(|s| !s.title.contains("Female"))
    .filter(|s| s.title.contains("Rate"))
    .enumerate()
    .for_each(|(i, s)| println!("{}\n{}", i, s));
    }
    /// Print unemployment_data for a given `Series`.
    /// ```
    /// unemployment_data("LRUNTTTTSIQ156S");
    /// ```
    pub fn unemployment_data(series_id: &str) -> String {
    let mut s = String::new();
    for obs in Fred::series_observations(series_id).observations {
    s.push_str(&format!(
    "{}, {}\n",
    obs.date,
    obs.value,
    ));
  • edit in src/lib.rs at line 45
    [2.110]
    [2.110]
    s.pop();
    s
  • edit in src/lib.rs at line 48
    [2.112]
  • file addition: countries.rs (-xw-xw-x--)
    [2.6]
    use std::fmt;
    pub enum Country {
    China,
    India,
    UnitedStates,
    Indonesia,
    Pakistan,
    Brazil,
    Nigeria,
    Bangladesh,
    Russia,
    Mexico,
    Japa,
    Ethiopia,
    Philippines,
    Egypt,
    Vietnam,
    DRCongo,
    Iran,
    Turkey,
    Germany,
    France,
    UnitedKingdom,
    Thailand,
    SouthAfrica,
    Tanzania,
    Italy,
    Myanmar,
    SouthKorea,
    Colombia,
    Kenya,
    Spain,
    Argentina,
    Algeria,
    Sudan,
    Uganda,
    Ukraine,
    Iraq,
    Canada,
    Poland,
    Morocco,
    Uzbekistan,
    SaudiArabia,
    Peru,
    Afghanistan,
    Malaysia,
    Angola,
    Ghana,
    Mozambique,
    Yemen,
    Nepal,
    Venezuela,
    IvoryCoast,
    Madagascar,
    Australia,
    NorthKorea,
    Cameroon,
    Niger,
    Taiwan,
    SriLanka,
    BurkinaFaso,
    Mali,
    Chile,
    Romania,
    Kazakhstan,
    Malawi,
    Zambia,
    Syria,
    Ecuador,
    Netherlands,
    Senegal,
    Guatemala,
    Chad,
    Somalia,
    Zimbabwe,
    Cambodia,
    SouthSudan,
    Rwanda,
    Guinea,
    Burundi,
    Benin,
    Bolivia,
    Haiti,
    Tunisia,
    Belgium,
    Cuba,
    Jordan,
    Greece,
    CzechRepublic,
    DominicanRepublic,
    Sweden,
    Portugal,
    Azerbaijan,
    Hungary,
    UnitedArabEmirates,
    Honduras,
    Belarus,
    Israel,
    Tajikistan,
    PapuaNewGuinea,
    Austria,
    Switzerland,
    SierraLeone,
    Togo,
    HongKong,
    Paraguay,
    Laos,
    Libya,
    Bulgaria,
    Serbia,
    ElSalvador,
    Lebanon,
    Kyrgyzstan,
    Nicaragua,
    Turkmenistan,
    Denmark,
    Singapore,
    Congo,
    CentralAfricanRepublic,
    Finland,
    Slovakia,
    Norway,
    Palestine,
    CostaRica,
    NewZealand,
    Ireland,
    Liberia,
    Oman,
    Kuwait,
    Panama,
    Mauritania,
    Croatia,
    Georgia,
    Eritrea,
    Uruguay,
    Mongolia,
    BosniaAndHerzegovina,
    PuertoRico,
    Armenia,
    Albania,
    Lithuania,
    Jamaica,
    Qatar,
    Moldova,
    Namibia,
    Botswana,
    Gambia,
    Gabon,
    Slovenia,
    NorthMacedonia,
    Lesotho,
    Latvia,
    Kosovo,
    GuineaBissau,
    Bahrain,
    EquatorialGuinea,
    TrinidadAndTobago,
    Estonia,
    EastTimor,
    Mauritius,
    Eswatini,
    Djibouti,
    Fiji,
    Cyprus,
    Comoros,
    Bhutan,
    Guyana,
    SolomonIslands,
    Macau,
    Luxembourg,
    Montenegro,
    WesternSahara,
    Suriname,
    CapeVerde,
    Malta,
    Transnistria,
    Brunei,
    Belize,
    Bahamas,
    Maldives,
    NorthernCyprus,
    Iceland,
    Vanuatu,
    Barbados,
    FrenchPolynesia,
    NewCaledonia,
    Abkhazia,
    SaoTomeAndPrincipe,
    Samoa,
    SaintLucia,
    Guam,
    Curacao,
    RepublicOfArtsakh,
    Kiribati,
    Grenada,
    Aruba,
    SaintVincentAndTheGrenadines,
    Jersey,
    FSMicronesia,
    USVirginIslands,
    Tonga,
    AntiguaAndBarbuda,
    Seychelles,
    IsleofMan,
    Andorra,
    Dominica,
    CaymanIslands,
    Bermuda,
    Guernsey,
    AmericanSamoa,
    NorthernMarianaIslands,
    Greenland,
    MarshallIslands,
    SaintKittsandNevis,
    SouthOssetia,
    FaroeIslands,
    TurksandCaicosIslands,
    SintMaarten,
    Liechtenstein,
    Monaco,
    SaintMartin,
    Gibraltar,
    SanMarino,
    AlandIslands,
    BritishVirginIslands,
    Palau,
    CookIslands,
    Anguilla,
    Nauru,
    WallisandFutuna,
    Tuvalu,
    SaintBarthelemy,
    SaintPierreAndMiquelon,
    SaintHelenaAndTristanDaCunha,
    Montserrat,
    FalklandIslands,
    ChristmasIsland,
    NorfolkIsland,
    Niue,
    Tokelau,
    VaticanCity,
    CocosKeelingIslands,
    PitcairnIslands,
    }
    impl fmt::Display for Country {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    let s = match self {
    Country::China => "China",
    Country::India => "India",
    Country::UnitedStates => "United States",
    Country::Indonesia => "Indonesia",
    Country::Pakistan => "Pakistan",
    Country::Brazil => "Brazil",
    Country::Nigeria => "Nigeria",
    Country::Bangladesh => "Bangladesh",
    Country::Russia => "Russia",
    Country::Mexico => "Mexico",
    Country::Japa => "Japa",
    Country::Ethiopia => "Ethiopia",
    Country::Philippines => "Philippines",
    Country::Egypt => "Egypt",
    Country::Vietnam => "Vietnam",
    Country::DRCongo => "DRCongo",
    Country::Iran => "Iran",
    Country::Turkey => "Turkey",
    Country::Germany => "Germany",
    Country::France => "France",
    Country::UnitedKingdom => "UnitedKingdom",
    Country::Thailand => "Thailand",
    Country::SouthAfrica => "SouthAfrica",
    Country::Tanzania => "Tanzania",
    Country::Italy => "Italy",
    Country::Myanmar => "Myanmar",
    Country::SouthKorea => "SouthKorea",
    Country::Colombia => "Colombia",
    Country::Kenya => "Kenya",
    Country::Spain => "Spain",
    Country::Argentina => "Argentina",
    Country::Algeria => "Algeria",
    Country::Sudan => "Sudan",
    Country::Uganda => "Uganda",
    Country::Ukraine => "Ukraine",
    Country::Iraq => "Iraq",
    Country::Canada => "Canada",
    Country::Poland => "Poland",
    Country::Morocco => "Morocco",
    Country::Uzbekistan => "Uzbekistan",
    Country::SaudiArabia => "SaudiArabia",
    Country::Peru => "Peru",
    Country::Afghanistan => "Afghanistan",
    Country::Malaysia => "Malaysia",
    Country::Angola => "Angola",
    Country::Ghana => "Ghana",
    Country::Mozambique => "Mozambique",
    Country::Yemen => "Yemen",
    Country::Nepal => "Nepal",
    Country::Venezuela => "Venezuela",
    Country::IvoryCoast => "Ivory Coast",
    Country::Madagascar => "Madagascar",
    Country::Australia => "Australia",
    Country::NorthKorea => "North Korea",
    Country::Cameroon => "Cameroon",
    Country::Niger => "Niger",
    Country::Taiwan => "Taiwan",
    Country::SriLanka => "SriLanka",
    Country::BurkinaFaso => "Burkina Faso",
    Country::Mali => "Mali",
    Country::Chile => "Chile",
    Country::Romania => "Romania",
    Country::Kazakhstan => "Kazakhstan",
    Country::Malawi => "Malawi",
    Country::Zambia => "Zambia",
    Country::Syria => "Syria",
    Country::Ecuador => "Ecuador",
    Country::Netherlands => "Netherlands",
    Country::Senegal => "Senegal",
    Country::Guatemala => "Guatemala",
    Country::Chad => "Chad",
    Country::Somalia => "Somalia",
    Country::Zimbabwe => "Zimbabwe",
    Country::Cambodia => "Cambodia",
    Country::SouthSudan => "South Sudan",
    Country::Rwanda => "Rwanda",
    Country::Guinea => "Guinea",
    Country::Burundi => "Burundi",
    Country::Benin => "Benin",
    Country::Bolivia => "Bolivia",
    Country::Haiti => "Haiti",
    Country::Tunisia => "Tunisia",
    Country::Belgium => "Belgium",
    Country::Cuba => "Cuba",
    Country::Jordan => "Jordan",
    Country::Greece => "Greece",
    Country::CzechRepublic => "CzechRepublic",
    Country::DominicanRepublic => "DominicanRepublic",
    Country::Sweden => "Sweden",
    Country::Portugal => "Portugal",
    Country::Azerbaijan => "Azerbaijan",
    Country::Hungary => "Hungary",
    Country::UnitedArabEmirates => "UnitedArabEmirates",
    Country::Honduras => "Honduras",
    Country::Belarus => "Belarus",
    Country::Israel => "Israel",
    Country::Tajikistan => "Tajikistan",
    Country::PapuaNewGuinea => "PapuaNewGuinea",
    Country::Austria => "Austria",
    Country::Switzerland => "Switzerland",
    Country::SierraLeone => "SierraLeone",
    Country::Togo => "Togo",
    Country::HongKong => "HongKong",
    Country::Paraguay => "Paraguay",
    Country::Laos => "Laos",
    Country::Libya => "Libya",
    Country::Bulgaria => "Bulgaria",
    Country::Serbia => "Serbia",
    Country::ElSalvador => "ElSalvador",
    Country::Lebanon => "Lebanon",
    Country::Kyrgyzstan => "Kyrgyzstan",
    Country::Nicaragua => "Nicaragua",
    Country::Turkmenistan => "Turkmenistan",
    Country::Denmark => "Denmark",
    Country::Singapore => "Singapore",
    Country::Congo => "Congo",
    Country::CentralAfricanRepublic => "CentralAfricanRepublic",
    Country::Finland => "Finland",
    Country::Slovakia => "Slovakia",
    Country::Norway => "Norway",
    Country::Palestine => "Palestine",
    Country::CostaRica => "CostaRica",
    Country::NewZealand => "NewZealand",
    Country::Ireland => "Ireland",
    Country::Liberia => "Liberia",
    Country::Oman => "Oman",
    Country::Kuwait => "Kuwait",
    Country::Panama => "Panama",
    Country::Mauritania => "Mauritania",
    Country::Croatia => "Croatia",
    Country::Georgia => "Georgia",
    Country::Eritrea => "Eritrea",
    Country::Uruguay => "Uruguay",
    Country::Mongolia => "Mongolia",
    Country::BosniaAndHerzegovina => "BosniaAndHerzegovina",
    Country::PuertoRico => "PuertoRico",
    Country::Armenia => "Armenia",
    Country::Albania => "Albania",
    Country::Lithuania => "Lithuania",
    Country::Jamaica => "Jamaica",
    Country::Qatar => "Qatar",
    Country::Moldova => "Moldova",
    Country::Namibia => "Namibia",
    Country::Botswana => "Botswana",
    Country::Gambia => "Gambia",
    Country::Gabon => "Gabon",
    Country::Slovenia => "Slovenia",
    Country::NorthMacedonia => "NorthMacedonia",
    Country::Lesotho => "Lesotho",
    Country::Latvia => "Latvia",
    Country::Kosovo => "Kosovo",
    Country::GuineaBissau => "GuineaBissau",
    Country::Bahrain => "Bahrain",
    Country::EquatorialGuinea => "EquatorialGuinea",
    Country::TrinidadAndTobago => "TrinidadAndTobago",
    Country::Estonia => "Estonia",
    Country::EastTimor => "EastTimor",
    Country::Mauritius => "Mauritius",
    Country::Eswatini => "Eswatini",
    Country::Djibouti => "Djibouti",
    Country::Fiji => "Fiji",
    Country::Cyprus => "Cyprus",
    Country::Comoros => "Comoros",
    Country::Bhutan => "Bhutan",
    Country::Guyana => "Guyana",
    Country::SolomonIslands => "SolomonIslands",
    Country::Macau => "Macau",
    Country::Luxembourg => "Luxembourg",
    Country::Montenegro => "Montenegro",
    Country::WesternSahara => "Western Sahara",
    Country::Suriname => "Suriname",
    Country::CapeVerde => "CapeVerde",
    Country::Malta => "Malta",
    Country::Transnistria => "Transnistria",
    Country::Brunei => "Brunei",
    Country::Belize => "Belize",
    Country::Bahamas => "Bahamas",
    Country::Maldives => "Maldives",
    Country::NorthernCyprus => "NorthernCyprus",
    Country::Iceland => "Iceland",
    Country::Vanuatu => "Vanuatu",
    Country::Barbados => "Barbados",
    Country::FrenchPolynesia => "FrenchPolynesia",
    Country::NewCaledonia => "New Caledonia",
    Country::Abkhazia => "Abkhazia",
    Country::SaoTomeAndPrincipe => "SãoToméAndPríncipe",
    Country::Samoa => "Samoa",
    Country::SaintLucia => "SaintLucia",
    Country::Guam => "Guam",
    Country::Curacao => "Curaçao",
    Country::RepublicOfArtsakh => "RepublicOfArtsakh",
    Country::Kiribati => "Kiribati",
    Country::Grenada => "Grenada",
    Country::Aruba => "Aruba",
    Country::SaintVincentAndTheGrenadines => "SaintVincentAndTheGrenadines",
    Country::Jersey => "Jersey",
    Country::FSMicronesia => "FSMicronesia",
    Country::USVirginIslands => "US Virgin Islands",
    Country::Tonga => "Tonga",
    Country::AntiguaAndBarbuda => "AntiguaAndBarbuda",
    Country::Seychelles => "Seychelles",
    Country::IsleofMan => "IsleofMan",
    Country::Andorra => "Andorra",
    Country::Dominica => "Dominica",
    Country::CaymanIslands => "CaymanIslands",
    Country::Bermuda => "Bermuda",
    Country::Guernsey => "Guernsey",
    Country::AmericanSamoa => "AmericanSamoa",
    Country::NorthernMarianaIslands => "NorthernMarianaIslands",
    Country::Greenland => "Greenland",
    Country::MarshallIslands => "MarshallIslands",
    Country::SaintKittsandNevis => "SaintKittsandNevis",
    Country::SouthOssetia => "SouthOssetia",
    Country::FaroeIslands => "FaroeIslands",
    Country::TurksandCaicosIslands => "TurksandCaicosIslands",
    Country::SintMaarten => "SintMaarten",
    Country::Liechtenstein => "Liechtenstein",
    Country::Monaco => "Monaco",
    Country::SaintMartin => "SaintMartin",
    Country::Gibraltar => "Gibraltar",
    Country::SanMarino => "San Marino",
    Country::AlandIslands => "ÅlandIslands",
    Country::BritishVirginIslands => "BritishVirginIslands",
    Country::Palau => "Palau",
    Country::CookIslands => "CookIslands",
    Country::Anguilla => "Anguilla",
    Country::Nauru => "Nauru",
    Country::WallisandFutuna => "WallisandFutuna",
    Country::Tuvalu => "Tuvalu",
    Country::SaintBarthelemy => "SaintBarthélemy",
    Country::SaintPierreAndMiquelon => "SaintPierreAndMiquelon",
    Country::SaintHelenaAndTristanDaCunha => "SaintHelenaAndTristanDaCunha",
    Country::Montserrat => "Montserrat",
    Country::FalklandIslands => "FalklandIslands",
    Country::ChristmasIsland => "ChristmasIsland",
    Country::NorfolkIsland => "NorfolkIsland",
    Country::Niue => "Niue",
    Country::Tokelau => "Tokelau",
    Country::VaticanCity => "VaticanCity",
    Country::CocosKeelingIslands => "CocosKeelingIslands",
    Country::PitcairnIslands => "PitcairnIslands",
    };
    write!(f, "{}", s)
    }
    }
  • edit in Cargo.toml at line 10
    [2.356]
    fred_api = { path = "../fred_api" }