Resolve warnings in fluent-ergonomics

This commit is contained in:
Savanni D'Gerinel 2023-10-04 16:25:29 -04:00
parent f1204faa5e
commit 598e9a01f8
2 changed files with 8 additions and 15 deletions

View File

@ -5,7 +5,6 @@ edition = "2018"
version = "0.2.0" version = "0.2.0"
description = "An ergonomics wrapper around Fluent-RS" description = "An ergonomics wrapper around Fluent-RS"
license = "GPL-3.0-only" license = "GPL-3.0-only"
license-file = "../COPYING"
homepage = "https://github.com/luminescent-dreams/fluent-ergonomics" homepage = "https://github.com/luminescent-dreams/fluent-ergonomics"
repository = "https://github.com/luminescent-dreams/fluent-ergonomics" repository = "https://github.com/luminescent-dreams/fluent-ergonomics"
categories = ["internationalization"] categories = ["internationalization"]

View File

@ -171,14 +171,14 @@ impl FluentErgo {
match entry { match entry {
Entry::Occupied(mut e) => { Entry::Occupied(mut e) => {
let bundle = e.get_mut(); let bundle = e.get_mut();
bundle.add_resource(res).map_err(|err| Error::from(err)) bundle.add_resource(res).map_err(Error::from)
} }
Entry::Vacant(e) => { Entry::Vacant(e) => {
let mut bundle: FluentBundle< let mut bundle: FluentBundle<
FluentResource, FluentResource,
intl_memoizer::concurrent::IntlLangMemoizer, intl_memoizer::concurrent::IntlLangMemoizer,
> = FluentBundle::new_concurrent(vec![lang]); > = FluentBundle::new_concurrent(vec![lang]);
bundle.add_resource(res).map_err(|err| Error::from(err))?; bundle.add_resource(res).map_err(Error::from)?;
e.insert(bundle); e.insert(bundle);
Ok(()) Ok(())
} }
@ -248,16 +248,10 @@ impl FluentErgo {
/// ///
pub fn tr(&self, msgid: &str, args: Option<&FluentArgs>) -> Result<String, Error> { pub fn tr(&self, msgid: &str, args: Option<&FluentArgs>) -> Result<String, Error> {
let bundles = self.bundles.read().unwrap(); let bundles = self.bundles.read().unwrap();
let result: Option<String> = self let result: Option<String> = self.languages.iter().find_map(|lang| {
.languages let bundle = bundles.get(lang)?;
.iter() self.tr_(bundle, msgid, args)
.map(|lang| { });
let bundle = bundles.get(lang)?;
self.tr_(bundle, msgid, args)
})
.filter(|v| v.is_some())
.map(|v| v.unwrap())
.next();
match result { match result {
Some(r) => Ok(r), Some(r) => Ok(r),
@ -276,8 +270,8 @@ impl FluentErgo {
let res = match pattern { let res = match pattern {
None => None, None => None,
Some(p) => { Some(p) => {
let res = bundle.format_pattern(&p, args, &mut errors); let res = bundle.format_pattern(p, args, &mut errors);
if errors.len() > 0 { if !errors.is_empty() {
println!("Errors in formatting: {:?}", errors) println!("Errors in formatting: {:?}", errors)
} }