[−][src]Derive Macro druid::Data
#[derive(Data)] { // Attributes available to this derive: #[data] }
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.
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(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>, }