pub(crate) fn generate_impl(mode: &Mode, params: Parameters) -> Result<TokenStream, TokenStream> {
    let target_fields = match params.target_struct.fields.clone() {
        Fields::Named(fields) => fields,
        _ => {
            return Err(err!(
                params.target_struct,
                "struct_merge only works on structs with named fields."
            ));
        }
    };
    let src_fields = match params.src_struct.fields.clone() {
        Fields::Named(fields) => fields,
        _ => {
            return Err(err!(
                params.target_struct,
                "struct_merge only works on structs with named fields."
            ));
        }
    };

    let mut similar_fields = Vec::new();
    for src_field in src_fields.named {
        for target_field in target_fields.named.clone() {
            if src_field.ident == target_field.ident {
                similar_fields.push((src_field.clone(), target_field));
            }
        }
    }

    // In the following, we'll generate all required functions for the `MergeInto` impl.
    // If any of the functions fails to be generated, we skip the impl for this struct.
    // The errors will be generated in the individual token generator functions.
    match *mode {
        Mode::Owned => Ok(owned::impl_owned(&params, similar_fields)),
        Mode::Borrowed => Ok(borrowed::impl_borrowed(&params, similar_fields)),
    }
}
/// Return a Tokenstream that contains all implementations to merge `src` into the `target`
/// struct.
///
/// Known Limitations:
/// - Error, when using different generic aliases that have same type.
/// - Visibility of the `target` struct isn't taken into account.
///     This will get better when module resolution is done properly.
/// - Type equality cannot be properly ensured at this stage.
///     Right now, we only check if the given tokens for a type are the same.
///     However, it's extremely difficult to found out the actual type from a simple token.
///
///     The resulting code will still be correct though, as any type issues will be caught by the
///     compiler anyway.
/// - If people work with type aliases such as `type nice = Option<String>`, the `Option` detection
///   no longer works and thereby the `merge_soft*` functions won't work as expected.
Return a Tokenstream that contains all implementations to merge `src` into the `target`
struct.

Known Limitations:
Error, when using different generic aliases that have same type.
Visibility of the `target` struct isn't taken into account.
This will get better when module resolution is done properly.
Type equality cannot be properly ensured at this stage.
Right now, we only check if the given tokens for a type are the same.
However, it's extremely difficult to found out the actual type from a simple token.

The resulting code will still be correct though, as any type issues will be caught by the
compiler anyway.
Return a Tokenstream that contains all implementations to merge ` src ` into the ` target ` struct . Known Limitations : Error when using different generic aliases that have same type . Visibility of the ` target ` struct isn ' t taken into account . This will get better when module resolution is done properly . Type equality cannot be properly ensured at this stage . Right now we only check if the given tokens for a type are the same . However it ' s extremely difficult to found out the actual type from a simple token . The resulting code will still be correct though as any type issues will be caught by the compiler anyway .
pub(crate) fn generate_impl(mode: &Mode, params: Parameters) -> Result<TokenStream, TokenStream> {
    let target_fields = match params.target_struct.fields.clone() {
        Fields::Named(fields) => fields,
        _ => {
            return Err(err!(
                params.target_struct,
                "struct_merge only works on structs with named fields."
            ));
        }
    };
    let src_fields = match params.src_struct.fields.clone() {
        Fields::Named(fields) => fields,
        _ => {
            return Err(err!(
                params.target_struct,
                "struct_merge only works on structs with named fields."
            ));
        }
    };
    let mut similar_fields = Vec::new();
    for src_field in src_fields.named {
        for target_field in target_fields.named.clone() {
            if src_field.ident == target_field.ident {
                similar_fields.push((src_field.clone(), target_field));
            }
        }
    }
    // In the following, we'll generate all required functions for the `MergeInto` impl.
    // If any of the functions fails to be generated, we skip the impl for this struct.
    // The errors will be generated in the individual token generator functions.
    match *mode {
        Mode::Owned => Ok(owned::impl_owned(&params, similar_fields)),
        Mode::Borrowed => Ok(borrowed::impl_borrowed(&params, similar_fields)),
    }
}
pub ( crate ) fn generate_impl ( mode : & Mode , params : Parameters ) -> Result < TokenStream , TokenStream > { let target_fields = match params . target_struct . fields . clone ( ) { Fields :: Named ( fields ) => fields , _ => { return Err ( err ! ( params target_struct " " ) ) ; } } ; let src_fields = match params . src_struct . fields . clone ( ) { Fields :: Named ( fields ) => fields , _ => { return Err ( err ! ( params target_struct " " ) ) ; } } ; let mut similar_fields = Vec :: new ( ) ; for src_field in src_fields . named { for target_field in target_fields . named . clone ( ) { if src_field . ident == target_field . ident { similar_fields . push ( ( src_field . clone ( ) , target_field ) ) ; } } } // In the following, we'll generate all required functions for the `MergeInto` impl. // If any of the functions fails to be generated, we skip the impl for this struct. // The errors will be generated in the individual token generator functions. match * mode { Mode :: Owned => Ok ( owned :: impl_owned ( & params , similar_fields ) ) , Mode :: Borrowed => Ok ( borrowed :: impl_borrowed ( & params , similar_fields ) ) , } }
Return a Tokenstream that contains all implementations to merge `src` into the `target`
struct.
Return a Tokenstream that contains all implementations to merge ` src ` into the ` target ` struct .
mode
&Mode
params
Parameters