mirror of
https://github.com/bytedream/serde-inline-default.git
synced 2025-05-08 19:55:13 +02:00
docs: update placement visibility (#11)
This commit is contained in:
parent
5fbcd2eb14
commit
6c014e41a6
@ -19,7 +19,7 @@ fn value_default() -> u32 { 42 }
|
||||
|
||||
That can get quiet messy if you have many fields with many (different) default values.
|
||||
This crate tries to solve this issue by providing the `#[serde_inline_default]` proc macro.
|
||||
With this macro set at the struct level (_**before `#[derive(Deserialize)]`/`#[derive(Serialize)]`!, otherwise it's not working correctly**_), you can set default values via `#[serde_inline_default(...)]` for your serde fields inline, without creating an extra function.
|
||||
With this macro set at the struct level, you can set default values via `#[serde_inline_default(...)]` for your serde fields inline, without creating an extra function.
|
||||
|
||||
```rust
|
||||
#[serde_inline_default]
|
||||
@ -30,6 +30,9 @@ struct Test {
|
||||
}
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
> **`#[serde_inline_default]` must be set before `#[derive(Deserialize)]`/`#[derive(Serialize)]`, otherwise it's not working correctly!**
|
||||
|
||||
Internally, `#[serde_inline_default(...)]` gets expanded to a function which returns the set value and the attribute is replaced with `#[serde(default = "<function name>")]`.
|
||||
So this macro is just some syntax sugar for you, but can get quiet handy if you want to keep your code clean or write declarative macros / `macro_rules!`.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user