Skip to content

Commit 532fa29

Browse files
committed
[src/code.rs] build_default_impl_fn now makes None the default for all Update fields
1 parent 668266d commit 532fa29

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/code.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ impl<'a> Struct<'a> {
412412
if self.config.options.default_impl {
413413
struct_code.push('\n');
414414
struct_code.push_str(&build_default_impl_fn(
415+
self.ty,
415416
&ty.format(&table.struct_name),
416417
&fields,
417418
));
@@ -793,14 +794,19 @@ fn default_for_type(typ: &str) -> &'static str {
793794
}
794795

795796
/// Generate default (insides of the `impl Default for StructName { fn default() -> Self {} }`)
796-
fn build_default_impl_fn<'a>(struct_name: &str, fields: &[StructField]) -> String {
797+
fn build_default_impl_fn<'a>(
798+
struct_type: StructType,
799+
struct_name: &str,
800+
fields: &[StructField],
801+
) -> String {
797802
let fields: Vec<String> = fields
798803
.iter()
799804
.map(|name_typ_nullable| {
800805
format!(
801806
"{name}: {typ_default},",
802807
name = name_typ_nullable.name,
803-
typ_default = if name_typ_nullable.is_optional {
808+
typ_default = if name_typ_nullable.is_optional || struct_type == StructType::Update
809+
{
804810
"None"
805811
} else {
806812
default_for_type(&name_typ_nullable.base_type)

0 commit comments

Comments
 (0)