From ecfe19f7e8046eab3608115b3ad3d77731b99f98 Mon Sep 17 00:00:00 2001 From: zaaarf Date: Mon, 12 Feb 2024 19:58:23 +0100 Subject: [PATCH] chore: error conversion implementation --- src/error.rs | 22 +++++++++++++--------- src/lib.rs | 4 ++-- 2 files changed, 15 insertions(+), 11 deletions(-) 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 {