diff --git a/src/error.rs b/src/error.rs index 04541a5..85e6774 100644 --- a/src/error.rs +++ b/src/error.rs @@ -4,30 +4,34 @@ use fluent::FluentResource; pub type Result = StdResult; +#[derive(Debug)] pub enum Error { - IoError(String) + IoError(std::io::Error), + LanguageIdentifierError(unic_langid::LanguageIdentifierError), + FluentError(Vec) } impl From for Error { - fn from(value: std::io::Error) -> Self { - todo!() + fn from(err: std::io::Error) -> Self { + Self::IoError(err) } } impl From<(FluentResource, Vec)> for Error { - fn from(value: (FluentResource, Vec)) -> Self { - todo!() + fn from(err: (FluentResource, Vec)) -> Self { + let err = err.1.iter().map(|e| fluent::FluentError::ParserError(e.clone())).collect(); + Self::FluentError(err) } } impl From> for Error { - fn from(value: Vec) -> Self { - todo!() + fn from(err: Vec) -> Self { + Self::FluentError(err) } } impl From for Error { - fn from(value: unic_langid::LanguageIdentifierError) -> Self { - todo!() + fn from(err: unic_langid::LanguageIdentifierError) -> Self { + Self::LanguageIdentifierError(err) } } diff --git a/src/lib.rs b/src/lib.rs index 49cc13a..7b12a93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,8 +8,8 @@ pub mod error; type TypedFluentBundle = FluentBundle, IntlLangMemoizer>; pub struct Localiser { - bundles: HashMap, - default_language: LanguageIdentifier + pub bundles: HashMap, + pub default_language: LanguageIdentifier } impl Localiser {