Permutations generator with early-exist


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 -

Any ideas how to write such a thing?