Skip to content

Commit

Permalink
Fixed issue where self referencing expressions would cause issues wit…
Browse files Browse the repository at this point in the history
…h `default(all)`
  • Loading branch information
ImaMapleTree committed Jun 8, 2024
1 parent 1214101 commit 1b97331
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "derive-ctor"
version = "1.0.3"
version = "1.0.4"
description = "Adds `#[derive(ctor)]` which allows for the auto-generation of struct, enum, and union constructors."
keywords = ["derive", "macro", "trait", "procedural", "no_std"]
authors = ["Evan Cowin"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Add `derive-ctor` to your `Cargo.toml`:

```toml
[dependencies]
derive-ctor = "1.0.3"
derive-ctor = "1.0.4"
```

Annotate your struct with `#[derive(ctor)]` to automatically generate a `new` constructor:
Expand Down
2 changes: 1 addition & 1 deletion src/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl FieldConfigProperty {
FieldConfigProperty::Default => true,
FieldConfigProperty::Into => false,
FieldConfigProperty::Iter { .. } => false,
FieldConfigProperty::Expression { .. } => true
FieldConfigProperty::Expression { self_referencing, .. } => !self_referencing
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions tests/struct_ctor_config_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ struct ImplementDefaultAllMembers {
#[ctor(expr(NoDefault {}))]
no_default: NoDefault,
#[ctor(into)]
provided: String
provided: String,
#[ctor(expr!(adjusted - 10))]
adjusted: i32
}

#[test]
Expand All @@ -73,8 +75,10 @@ fn test_struct_implement_default_all_members() {
name: Default::default(),
value: Default::default(),
no_default: NoDefault {},
provided: Default::default()
provided: Default::default(),
adjusted: 0,
},
result
);
}

0 comments on commit 1b97331

Please sign in to comment.