Permutations generator with early-exist

#1

I’m looking for a way to write a code that will allow me to test every permutation of [paths]x[sources] while allowing at the same time to bail out of a branch early if path+source ends up being None.

To give the scenario an example:

let paths = &["menu.ftl", "common.ftl"];
let sources = &["toolkit", "browser"];

now I want an Iterator over [("menu.ftl", "browser"), ("common.ftl", "browser")], [("menu.ftl", "browser"), ("common.ftl", "toolkit")] and so on, but if in step (1) I learn that ("menu.ftl", "browser") doesn’t exist, I want to exit that branch and skip trying to build the [("menu.ftl", "browser"), ("common.ftl", "toolkit")], and the following next() should attempt `[(“menu.ftl”, “toolkit”), (“common.ftl”, “browser”)]``.

I found a couple crates related to Cartesian product and permutations, but they don’t seem a good way to bail out of a branch early.
In JS I’m using a recursive generators, which don’t exist in Rust yet as far as I know - https://searchfox.org/mozilla-central/rev/78cd247b5d7a08832f87d786541d3e2204842e8e/intl/l10n/L10nRegistry.jsm#283

Any ideas how to write such a thing?

#2

Voilà