summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-05-26 17:53:17 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-05-28 11:54:59 +0000
commit4ef323a9838d057ff1c03375066a2c3dc1c183a4 (patch)
tree85b630f9464f26784a849bf341a334fcbdb28fea /android
parent5be3f7e9ad63081cce466b313b44840f80227c29 (diff)
downloadmullvadvpn-4ef323a9838d057ff1c03375066a2c3dc1c183a4.tar.xz
mullvadvpn-4ef323a9838d057ff1c03375066a2c3dc1c183a4.zip
Implement `FromStr` for `PluralForm`
Makes it simpler to obtain an error when attempting to create an instance from a formula string.
Diffstat (limited to 'android')
-rw-r--r--android/translations-converter/src/gettext/plural_form.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/android/translations-converter/src/gettext/plural_form.rs b/android/translations-converter/src/gettext/plural_form.rs
index c55066c7b7..e09e9cfd04 100644
--- a/android/translations-converter/src/gettext/plural_form.rs
+++ b/android/translations-converter/src/gettext/plural_form.rs
@@ -1,3 +1,6 @@
+use derive_more::{Display, Error};
+use std::str::FromStr;
+
/// Known plural forms.
#[derive(Clone, Copy, Debug)]
pub enum PluralForm {
@@ -29,3 +32,19 @@ impl PluralForm {
}
}
}
+
+impl FromStr for PluralForm {
+ type Err = UnsupportedPluralFormulaError;
+
+ fn from_str(string: &str) -> Result<Self, Self::Err> {
+ PluralForm::from_formula(string)
+ .ok_or_else(|| UnsupportedPluralFormulaError(string.to_owned()))
+ }
+}
+
+/// Failed to create [`PluralForm`] from specified plural formula.
+///
+/// The formula could be an invalid formula, or support for it hasn't been added yet.
+#[derive(Clone, Debug, Display, Error)]
+#[display(fmt = "Unsupported plural formula: {}", _0)]
+pub struct UnsupportedPluralFormulaError(#[error(not(source))] String);