summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author zaaarf <me@zaaarf.foo>2024-02-12 19:58:23 +0100
committer zaaarf <me@zaaarf.foo>2024-02-12 19:58:23 +0100
commitecfe19f7e8046eab3608115b3ad3d77731b99f98 (patch)
tree7ae42a659b64a04469b98c0a3f1f3448fa827353
parent0a759cfc2977cee65c2acc0845b3c471c401a3d3 (diff)
chore: error conversion implementation
-rw-r--r--src/error.rs22
-rw-r--r--src/lib.rs4
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<T> = StdResult<T, Error>;
+#[derive(Debug)]
pub enum Error {
- IoError(String)
+ IoError(std::io::Error),
+ LanguageIdentifierError(unic_langid::LanguageIdentifierError),
+ FluentError(Vec<fluent::FluentError>)
}
impl From<std::io::Error> for Error {
- fn from(value: std::io::Error) -> Self {
- todo!()
+ fn from(err: std::io::Error) -> Self {
+ Self::IoError(err)
}
}
impl From<(FluentResource, Vec<fluent_syntax::parser::ParserError>)> for Error {
- fn from(value: (FluentResource, Vec<fluent_syntax::parser::ParserError>)) -> Self {
- todo!()
+ fn from(err: (FluentResource, Vec<fluent_syntax::parser::ParserError>)) -> Self {
+ let err = err.1.iter().map(|e| fluent::FluentError::ParserError(e.clone())).collect();
+ Self::FluentError(err)
}
}
impl From<Vec<fluent::FluentError>> for Error {
- fn from(value: Vec<fluent::FluentError>) -> Self {
- todo!()
+ fn from(err: Vec<fluent::FluentError>) -> Self {
+ Self::FluentError(err)
}
}
impl From<unic_langid::LanguageIdentifierError> 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<Arc<FluentResource>, IntlLangMemoizer>;
pub struct Localiser {
- bundles: HashMap<LanguageIdentifier, TypedFluentBundle>,
- default_language: LanguageIdentifier
+ pub bundles: HashMap<LanguageIdentifier, TypedFluentBundle>,
+ pub default_language: LanguageIdentifier
}
impl Localiser {