fn distribute_and_unnest_attrs(
    input: &mut Vec<Attribute>,
    outputs: &mut [(&'static str, &mut Vec<Attribute>)],
) -> darling::Result<()> {
    let mut errors = vec![];

    for (name, list) in &*outputs {
        assert!(list.is_empty(), "Output Vec for '{}' was not empty", name);
    }

    for attr in input.drain(..) {
        let destination = outputs
            .iter_mut()
            .find(|(ptattr, _)| attr.path.is_ident(ptattr));

        if let Some((_, destination)) = destination {
            match unnest_from_one_attribute(attr) {
                Ok(n) => destination.push(n),
                Err(e) => errors.push(e),
            }
        } else {
            for (_, output) in outputs.iter_mut() {
                output.push(attr.clone());
            }
        }
    }

    if !errors.is_empty() {
        return Err(darling::Error::multiple(errors));
    }

    Ok(())
}
/// Divide a list of attributes into multiple partially-overlapping output lists.
///
/// Some attributes from the macro input will be added to the output in multiple places;
/// for example, a `cfg` attribute must be replicated to both the struct and its impl block or
/// the resulting code will not compile.
///
/// Other attributes are scoped to a specific output by their path, e.g. `builder_field_attr`.
/// These attributes will only appear in one output list, but need that outer path removed.
///
/// For performance reasons, we want to do this in one pass through the list instead of
/// first distributing and then iterating through each of the output lists.
///
/// Each item in `outputs` contains the attribute name unique to that output, and the `Vec` where all attributes for that output should be inserted.
/// Attributes whose path matches any value in `outputs` will be added only to the first matching one, and will be "unnested".
/// Other attributes are not unnested, and simply copied for each decoratee.
Divide a list of attributes into multiple partially-overlapping output lists.
Some attributes from the macro input will be added to the output in multiple places;
for example, a `cfg` attribute must be replicated to both the struct and its impl block or
the resulting code will not compile.

Other attributes are scoped to a specific output by their path, e.g.

For performance reasons, we want to do this in one pass through the list instead of
first distributing and then iterating through each of the output lists.

Each item in `outputs` contains the attribute name unique to that output, and the `Vec` where all attributes for that output should be inserted.
Attributes whose path matches any value in `outputs` will be added only to the first matching one, and will be "unnested".
Other attributes are not unnested, and simply copied for each decoratee.
Divide a list of attributes into multiple partially - overlapping output lists . Some attributes from the macro input will be added to the output in multiple places ; for example a ` cfg ` attribute must be replicated to both the struct and its impl block or the resulting code will not compile . Other attributes are scoped to a specific output by their path e . g . For performance reasons we want to do this in one pass through the list instead of first distributing and then iterating through each of the output lists . Each item in ` outputs ` contains the attribute name unique to that output and the ` Vec ` where all attributes for that output should be inserted . Attributes whose path matches any value in ` outputs ` will be added only to the first matching one and will be " unnested " . Other attributes are not unnested and simply copied for each decoratee .
fn distribute_and_unnest_attrs(
    input: &mut Vec<Attribute>,
    outputs: &mut [(&'static str, &mut Vec<Attribute>)],
) -> darling::Result<()> {
    let mut errors = vec![];
    for (name, list) in &*outputs {
        assert!(list.is_empty(), "Output Vec for '{}' was not empty", name);
    }
    for attr in input.drain(..) {
        let destination = outputs
            .iter_mut()
            .find(|(ptattr, _)| attr.path.is_ident(ptattr));
        if let Some((_, destination)) = destination {
            match unnest_from_one_attribute(attr) {
                Ok(n) => destination.push(n),
                Err(e) => errors.push(e),
            }
        } else {
            for (_, output) in outputs.iter_mut() {
                output.push(attr.clone());
            }
        }
    }
    if !errors.is_empty() {
        return Err(darling::Error::multiple(errors));
    }
    Ok(())
}
fn distribute_and_unnest_attrs ( input : & mut Vec < Attribute > , outputs : & mut [ ( & ' static str , & mut Vec < Attribute > ) ] , ) -> darling :: Result < ( ) > { let mut errors = vec ! [ ] ; for ( name , list ) in & * outputs { assert ! ( list is_empty ( ) " " name ) ; } for attr in input . drain ( .. ) { let destination = outputs . iter_mut ( ) . find ( | ( ptattr , _ ) | attr . path . is_ident ( ptattr ) ) ; if let Some ( ( _ , destination ) ) = destination { match unnest_from_one_attribute ( attr ) { Ok ( n ) => destination . push ( n ) , Err ( e ) => errors . push ( e ) , } } else { for ( _ , output ) in outputs . iter_mut ( ) { output . push ( attr . clone ( ) ) ; } } } if ! errors . is_empty ( ) { return Err ( darling :: Error :: multiple ( errors ) ) ; } Ok ( ( ) ) }
Divide a list of attributes into multiple partially-overlapping output lists.
Divide a list of attributes into multiple partially - overlapping output lists .
input
&mut Vec<Attribute>
outputs
&mut [(&'static str, &mut Vec<Attribute>)]
input
&mut Vec<Attribute>
outputs
&mut [(&'static str, &mut Vec<Attribute>)]