Skip to content

Commit

Permalink
Merge 8c6714d into e8795fb
Browse files Browse the repository at this point in the history
  • Loading branch information
zbraniecki committed Mar 13, 2020
2 parents e8795fb + 8c6714d commit c47f677
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions fluent-fallback/src/lib.rs
Expand Up @@ -6,37 +6,48 @@ use fluent_bundle::{FluentArgs, FluentBundle};

use reiterate::Reiterate;

struct FluentBundleIterator<'loc, R> {
iter: Box<dyn Iterator<Item = FluentBundle<R>> + 'loc>,
struct FluentBundleIterator<R, I>
where
I: Iterator<Item = FluentBundle<R>>,
{
iter: I,
}

impl<'loc, R> Iterator for FluentBundleIterator<'loc, R> {
impl<R, I> Iterator for FluentBundleIterator<R, I>
where
I: Iterator<Item = FluentBundle<R>>,
{
type Item = Box<FluentBundle<R>>;
fn next(&mut self) -> Option<Self::Item> {
self.iter.next().map(Box::new)
}
}

pub struct Localization<'loc, R> {
pub struct Localization<'loc, R, I>
where
I: Iterator<Item = FluentBundle<R>> + 'loc,
{
pub resource_ids: Vec<String>,
bundles: Reiterate<FluentBundleIterator<'loc, R>>,
generate_bundles: Box<dyn FnMut(&[String]) -> FluentBundleIterator<'loc, R> + 'loc>,
bundles: Reiterate<FluentBundleIterator<R, I>>,
generate_bundles: Box<dyn FnMut(&[String]) -> FluentBundleIterator<R, I> + 'loc>,
}

impl<'loc, R> Localization<'loc, R> {
pub fn new<F, I>(resource_ids: Vec<String>, mut generate_bundles: F) -> Self
impl<'loc, R, I> Localization<'loc, R, I>
where
I: Iterator<Item = FluentBundle<R>>,
{
pub fn new<F>(resource_ids: Vec<String>, mut generate_bundles: F) -> Self
where
F: FnMut(&[String]) -> I + 'loc,
I: Iterator<Item = FluentBundle<R>> + 'loc,
{
let mut generate2 = move |x: &[String]| FluentBundleIterator {
iter: Box::new(generate_bundles(x)),
let mut generate = move |x: &[String]| FluentBundleIterator {
iter: generate_bundles(x),
};
let bundles = Reiterate::new(generate2(&resource_ids));
let bundles = Reiterate::new(generate(&resource_ids));
Localization {
resource_ids,
bundles,
generate_bundles: Box::new(generate2),
generate_bundles: Box::new(generate),
}
}

Expand Down

0 comments on commit c47f677

Please sign in to comment.