-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow specifying arbitrary attributes on the builder struct (#237)
* Field: Distinguish field from setter attributes * Support builder_field_attr(...) * Support builder_setter_attr(...)
- Loading branch information
Showing
8 changed files
with
164 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#[macro_use] | ||
extern crate derive_builder; | ||
|
||
#[derive(Debug, PartialEq, Default, Builder, Clone)] | ||
pub struct Lorem { | ||
ok: String, | ||
|
||
#[builder_field_attr(no_such_attribute)] | ||
broken: String, | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: cannot find attribute `no_such_attribute` in this scope | ||
--> tests/compile-fail/builder_field_attr.rs:8:26 | ||
| | ||
8 | #[builder_field_attr(no_such_attribute)] | ||
| ^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#![deny(unused_must_use)] | ||
|
||
#[macro_use] | ||
extern crate derive_builder; | ||
|
||
#[derive(Debug, PartialEq, Default, Builder, Clone)] | ||
pub struct Lorem { | ||
ok: String, | ||
|
||
#[builder_setter_attr(must_use)] | ||
broken: usize, | ||
} | ||
|
||
fn main() { | ||
LoremBuilder::default().broken(42); | ||
} |
11 changes: 11 additions & 0 deletions
11
derive_builder/tests/compile-fail/builder_setter_attr.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: unused return value of `LoremBuilder::broken` that must be used | ||
--> tests/compile-fail/builder_setter_attr.rs:15:5 | ||
| | ||
15 | LoremBuilder::default().broken(42); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> tests/compile-fail/builder_setter_attr.rs:1:9 | ||
| | ||
1 | #![deny(unused_must_use)] | ||
| ^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters