#[derive(Delta)]
{
// Attributes available to this derive:
#[delta_struct]
}
Expand description
Derives Delta, generating a {Self}Delta struct that holds only the
changed parts of a value plus the trait implementation that produces and
applies one.
The generated struct takes the visibility and generic parameters of the
type it is derived on, and all of its fields are pub. See the
delta-struct crate documentation for the
full picture, including trait bounds, serde usage, and limitations; what
follows is the attribute reference.
§Container attributes
| Attribute | Effect |
|---|---|
default = "<field type>" | Field type for fields that don’t specify one. Defaults to "scalar". |
delta_leader = "<tokens>" | Tokens emitted directly above the generated struct — derives, doc comments, anything. |
§Field attributes
| Attribute | Effect |
|---|---|
field_type = "<field type>" | How this field is diffed. Overrides the container’s default. |
delta_leader = "<tokens>" | Tokens emitted directly above the generated field. On an unordered field they land above both the _add and the _remove field. |
§Field types
| Value | Delta representation | Requires |
|---|---|---|
"scalar" | Option<T> | T: PartialEq |
"unordered" | {field}_add and {field}_remove, both Vec<Item> | T: IntoIterator + FromIterator<Item> + Extend<Item>, Item: PartialEq |
"ordered" | SeqDelta<Item>, a Myers edit script | T: IntoIterator + FromIterator<Item>, Item: Hash + Eq |
"delta" | Option<<T as Delta>::Output> | T: Delta |
§Example
ⓘ
use delta_struct::Delta;
#[derive(Delta)]
#[delta_struct(delta_leader = "#[derive(Debug)]")]
struct Device {
#[delta_struct(field_type = "unordered")]
services: Vec<String>,
online: bool,
}The example is not run as a doctest because this crate cannot depend on the
crate that re-exports it; the tested versions live in the delta-struct
crate documentation.