pub fn literals<'i, 't, A, I>(
    tokens: I,
) -> impl Iterator<Item = (Component<'i, 't, A>, LiteralSequence<'i, 't>)>
where
    't: 'i,
    A: 't,
    I: IntoIterator<Item = &'i Token<'t, A>>,
{
    components(tokens).flat_map(|component| {
        if let Some(literal) = component.literal() {
            vec![(component, literal)]
        }
        else {
            component
                .tokens()
                .iter()
                .filter_map(|token| match token.kind() {
                    TokenKind::Alternative(ref alternative) => Some(
                        alternative
                            .branches()
                            .iter()
                            .flat_map(literals)
                            .collect::<Vec<_>>(),
                    ),
                    TokenKind::Repetition(ref repetition) => {
                        Some(literals(repetition.tokens()).collect::<Vec<_>>())
                    },
                    _ => None,
                })
                .flatten()
                .collect::<Vec<_>>()
        }
    })
}
// TODO: This implementation allocates many `Vec`s.
This implementation allocates many `Vec`s.
This implementation allocates many ` Vec ` s .
pub fn literals<'i, 't, A, I>(
    tokens: I,
) -> impl Iterator<Item = (Component<'i, 't, A>, LiteralSequence<'i, 't>)>
where
    't: 'i,
    A: 't,
    I: IntoIterator<Item = &'i Token<'t, A>>,
{
    components(tokens).flat_map(|component| {
        if let Some(literal) = component.literal() {
            vec![(component, literal)]
        }
        else {
            component
                .tokens()
                .iter()
                .filter_map(|token| match token.kind() {
                    TokenKind::Alternative(ref alternative) => Some(
                        alternative
                            .branches()
                            .iter()
                            .flat_map(literals)
                            .collect::<Vec<_>>(),
                    ),
                    TokenKind::Repetition(ref repetition) => {
                        Some(literals(repetition.tokens()).collect::<Vec<_>>())
                    },
                    _ => None,
                })
                .flatten()
                .collect::<Vec<_>>()
        }
    })
}
pub fn literals < ' i , ' t , A , I > ( tokens : I , ) -> impl Iterator < Item = ( Component < ' i , ' t , A > , LiteralSequence < ' i , ' t > ) > where ' t : ' i , A : ' t , I : IntoIterator < Item = & ' i Token < ' t , A > > , { components ( tokens ) . flat_map ( | component | { if let Some ( literal ) = component . literal ( ) { vec ! [ ( component literal ) ] } else { component . tokens ( ) . iter ( ) . filter_map ( | token | match token . kind ( ) { TokenKind :: Alternative ( ref alternative ) => Some ( alternative . branches ( ) . iter ( ) . flat_map ( literals ) . collect :: < Vec < _ > > ( ) , ) , TokenKind :: Repetition ( ref repetition ) => { Some ( literals ( repetition . tokens ( ) ) . collect :: < Vec < _ > > ( ) ) } , _ => None , } ) . flatten ( ) . collect :: < Vec < _ > > ( ) } } ) }
TODO: This implementation allocates many `Vec`s.
TODO : This implementation allocates many ` Vec ` s .
tokens
I
tokens
I