Repository: diesel-rs/diesel
File: diesel_derives/src/as_changeset.rs (Rust)

Code before:
    let (_, ty_generics, where_clause) = item.generics.split_for_impl();
    let mut impl_generics = item.generics.clone();
    impl_generics.params.push(parse_quote!('update));
    let (impl_generics, _, _) = impl_generics.split_for_impl();

    let fields_for_update = model
        .fields()
        .iter()
        .filter(|f| !model.primary_key_names.contains(&f.column_name_ident()))
        .collect::<Vec<_>>();
    if fields_for_update.is_empty() {
        Span::call_site()
            .error(
                "Deriving `AsChangeset` on a structure that only contains the primary key isn't supported."
            )
            .help("If you want to change the primary key of a row, you should do so with `.set(table::id.eq(new_id))`.")
            .note("`#[derive(AsChangeset)]` never changes the primary key of a row.")
            .emit();
    }

    let mut generate_borrowed_changeset = true;

    let mut direct_changeset_ty = Vec::with_capacity(fields_for_update.len());
    let mut direct_changeset_expr = Vec::with_capacity(fields_for_update.len());
    let mut ref_changeset_ty = Vec::with_capacity(fields_for_update.len());
    let mut ref_changeset_expr = Vec::with_capacity(fields_for_update.len());

    for field in fields_for_update {
        if let Some(ty) = field.ty_for_serialize()? {
            direct_changeset_ty.push(field_changeset_ty_serialize_as(
                field,
                &table_name,
                treat_none_as_null,
                &ty,
            ));
            direct_changeset_expr.push(field_changeset_expr_serialize_as(
                field,
                &table_name,
                treat_none_as_null,
                &ty,
            ));

            generate_borrowed_changeset = false; // as soon as we hit one field with #[diesel(serialize_as)] there is no point in generating the impl of AsChangeset for borrowed structs
        } else {
            direct_changeset_ty.push(field_changeset_ty(
                field,
                &table_name,
                treat_none_as_null,
                None,
            ));
            direct_changeset_expr.push(field_changeset_expr(

Review comment (suggestion):
Don't like the fact that we moved away from `map`.

Code after:
        })
        .collect::<Vec<_>>();

    if fields_for_update.is_empty() {
        abort_call_site!(
            "Deriving `AsChangeset` on a structure that only contains primary keys isn't supported.";
            help = "If you want to change the primary key of a row, you should do so with `.set(table::id.eq(new_id))`.";
            note = "`#[derive(AsChangeset)]` never changes the primary key of a row.";
        )
    }

    let treat_none_as_null = model.treat_none_as_null();

    let (_, ty_generics, where_clause) = item.generics.split_for_impl();
    let mut impl_generics = item.generics.clone();
    impl_generics.params.push(parse_quote!('update));
    let (impl_generics, _, _) = impl_generics.split_for_impl();

    let mut generate_borrowed_changeset = true;

    let mut direct_field_ty = Vec::with_capacity(fields_for_update.len());
    let mut direct_field_assign = Vec::with_capacity(fields_for_update.len());
    let mut ref_field_ty = Vec::with_capacity(fields_for_update.len());
    let mut ref_field_assign = Vec::with_capacity(fields_for_update.len());

    for field in fields_for_update {
        match field.serialize_as.as_ref() {
            Some(AttributeSpanWrapper { item: ty, .. }) => {
                direct_field_ty.push(field_changeset_ty_serialize_as(
                    field,
                    table_name,
                    ty,
                    treat_none_as_null,
                ));
                direct_field_assign.push(field_changeset_expr_serialize_as(
                    field,
                    table_name,
                    ty,
                    treat_none_as_null,
                ));

                generate_borrowed_changeset = false; // as soon as we hit one field with #[diesel(serialize_as)] there is no point in generating the impl of AsChangeset for borrowed structs
            }
            None => {
                direct_field_ty.push(field_changeset_ty(
                    field,
                    table_name,
                    None,
                    treat_none_as_null,
                ));
                direct_field_assign.push(field_changeset_expr(