Derive Macro druid_derive::Data [−][src]
#[derive(Data)]
{
// Attributes available to this derive:
#[data]
}
Expand description
Generates implementations of the Data
trait.
This macro supports a data
field attribute with the following arguments:
#[data(ignore)]
makes the generatedData::same
function skip comparing this field.#[data(same_fn="foo")]
uses the functionfoo
for comparing this field.foo
should be the name of a function with signaturefn(&T, &T) -> bool
, whereT
is the type of the field.#[data(eq)]
is shorthand for#[data(same_fn = "PartialEq::eq")]
Example
use druid_derive::Data;
#[derive(Clone, Data)]
struct State {
number: f64,
// `Vec` doesn't implement `Data`, so we need to either ignore it or supply a `same_fn`.
#[data(eq)]
// same as #[data(same_fn="PartialEq::eq")]
indices: Vec<usize>,
// This is just some sort of cache; it isn't important for sameness comparison.
#[data(ignore)]
cached_indices: Vec<usize>,
}