#[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::samefunction skip comparing this field.#[data(same_fn="foo")]uses the functionfoofor comparing this field.fooshould be the name of a function with signaturefn(&T, &T) -> bool, whereTis 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>,
}