1pub mod error;
7pub mod config;
8pub mod parser;
9
10pub use error::ParseError;
12pub use config::{Configuration, CountryInfo, ParserSettings};
13
14pub use isocountry::CountryCode;
16
17pub fn parse_country_code(text: &str) -> Result<CountryCode, ParseError> {
28 parser::parse_country_code(text)
29}
30
31#[derive(Debug, Clone)]
33pub struct ParserConfig {
34 pub case_sensitive: bool,
36 pub fuzzy_match: bool,
38 pub timeout_ms: u64,
40}
41
42impl Default for ParserConfig {
43 fn default() -> Self {
44 Self {
45 case_sensitive: false,
46 fuzzy_match: true,
47 timeout_ms: 100,
48 }
49 }
50}
51
52pub struct Parser {
54 config: ParserConfig,
55}
56
57impl Parser {
58 pub fn new() -> Self {
60 Self {
61 config: ParserConfig::default(),
62 }
63 }
64
65 pub fn with_config(config: ParserConfig) -> Self {
67 Self { config }
68 }
69
70 pub fn parse(&self, text: &str) -> Result<CountryCode, ParseError> {
72 parser::parse_country_code_with_config(text, &self.config)
73 }
74}
75
76impl Default for Parser {
77 fn default() -> Self {
78 Self::new()
79 }
80}