locale_types/
lib.rs

1/*!
2Idiomatic types for locale identifiers.
3
4This crate provides a [`Locale`](locale/enum.Locale.html) enumeration,
5[`LocaleIdentifier`](id/trait.LocaleIdentifier.html) trait, and a
6[`LocaleString`](string/struct.LocaleString.html) structure are provided that
7may be used to parse and construct locale identifiers in a
8standards-conformant manner.
9
10## Example
11
12```
13use locale_types::{LocaleIdentifier, LocaleString};
14
15let locale = LocaleString::new("en".to_string()).unwrap()
16    .with_territory("US".to_string()).unwrap()
17    .with_code_set("UTF-8".to_string()).unwrap()
18    .with_modifier("collation=pinyin;currency=CNY".to_string()).unwrap();
19println!("{}", locale);
20```
21
22*/
23
24#![warn(
25    missing_debug_implementations,
26    missing_docs,
27    unused_extern_crates,
28    rust_2018_idioms
29)]
30
31#[macro_use]
32extern crate lazy_static;
33
34// ------------------------------------------------------------------------------------------------
35// Public Types
36// ------------------------------------------------------------------------------------------------
37
38/// Common error type for functions in this crate.
39#[derive(Debug, PartialEq)]
40pub enum LocaleError {
41    /// The provided locale string was badly formatted
42    InvalidLocaleString,
43    /// The provided language code was not valid, or was unknown.
44    InvalidLanguageCode,
45    /// The provided territory code was not valid, or was unknown.
46    InvalidTerritoryCode,
47    /// The provided code set name was not valid, or was unknown.
48    InvalidCodeSet,
49    /// The provided modifier string was not valid, or was unknown.
50    InvalidModifier,
51    /// The provided locale was unknown
52    UnknownLocale,
53    /// Locale category not set/or supported
54    UnsetCategory,
55    /// Operating system could not set the specified locale
56    OSError,
57    /// The operation you tried to perform was not supported.
58    Unsupported,
59}
60
61/// Common result type for functions in this crate.
62pub type LocaleResult<T> = Result<T, LocaleError>;
63
64// ------------------------------------------------------------------------------------------------
65// Public Modules
66// ------------------------------------------------------------------------------------------------
67
68pub mod id;
69pub use id::LocaleIdentifier;
70
71pub mod string;
72pub use string::LocaleString;
73
74pub mod locale;
75pub use locale::Locale;