world_region/
from_str.rs

1// ---------------- [ File: src/from_str.rs ]
2crate::ix!();
3
4impl FromStr for WorldRegion {
5    type Err = WorldRegionParseError;
6
7    fn from_str(input: &str) -> Result<Self, Self::Err> {
8        let s = input.trim();
9        let s = s.to_lowercase();
10
11        // Try subregions directly:
12        if let Ok(fr) = s.parse::<AfricaRegion>() {
13            return Ok(WorldRegion::Africa(fr));
14        }
15        if let Ok(gr) = s.parse::<AsiaRegion>() {
16            return Ok(WorldRegion::Asia(gr));
17        }
18        if let Ok(ir) = s.parse::<EuropeRegion>() {
19            return Ok(WorldRegion::Europe(ir));
20        }
21        if let Ok(nr) = s.parse::<NorthAmericaRegion>() {
22            return Ok(WorldRegion::NorthAmerica(nr));
23        }
24        if let Ok(pr) = s.parse::<SouthAmericaRegion>() {
25            return Ok(WorldRegion::SouthAmerica(pr));
26        }
27        if let Ok(rr) = s.parse::<CentralAmericaRegion>() {
28            return Ok(WorldRegion::CentralAmerica(rr));
29        }
30        if let Ok(sr) = s.parse::<AustraliaOceaniaAntarcticaRegion>() {
31            return Ok(WorldRegion::AustraliaOceaniaAntarctica(sr));
32        }
33
34        Err(WorldRegionParseError::UnknownVariant(s.to_string()))
35    }
36}