1use crate::source::{from_iter, FromIter};
23/// Builds a source that chains sources built from a factory.
4///
5/// The `factory` parameter is a function that produces a source. The source is then played.
6/// Whenever the source ends, `factory` is called again in order to produce the source that is
7/// played next.
8///
9/// If the `factory` closure returns `None`, then the sound ends.
10pub fn from_factory<F, S>(factory: F) -> FromIter<FromFactoryIter<F>>
11where
12F: FnMut() -> Option<S>,
13{
14 from_iter(FromFactoryIter { factory })
15}
1617/// Internal type used by `from_factory`.
18pub struct FromFactoryIter<F> {
19 factory: F,
20}
2122impl<F, S> Iterator for FromFactoryIter<F>
23where
24F: FnMut() -> Option<S>,
25{
26type Item = S;
2728#[inline]
29fn next(&mut self) -> Option<S> {
30 (self.factory)()
31 }
3233#[inline]
34fn size_hint(&self) -> (usize, Option<usize>) {
35 (0, None)
36 }
37}