pub trait Data: Clone + 'static {
    // Required method
    fn same(&self, other: &Self) -> bool;
}
Expand description

A trait used to represent value types.

These should be cheap to compare and cheap to clone.

See https://sinusoid.es/lager/model.html#id2 for a well-written explanation of value types (albeit within a C++ context).

Derive macro

In general, you can use derive to generate a Data impl for your types.

#[derive(Clone, Data)]
enum Foo {
    Case1(i32, f32),
    Case2 { a: String, b: Arc<i32> }
}

Derive macro attributes

There are a number of field attributes available for use with derive(Data).

  • #[data(ignore)]

Skip this field when computing sameness.

If the type you are implementing Data on contains some fields that are not relevant to the Data impl, you can ignore them with this attribute.

  • #[data(same_fn = "path")]

Use a specific function to compute sameness.

By default, derived implementations of Data just call Data::same recursively on each field. With this attribute, you can specify a custom function that will be used instead.

This function must have a signature in the form, fn<T>(&T, &T) -> bool, where T is the type of the field.

Collection types

Data is not implemented for std collection types, because comparing them can be expensive. To use collection types with Druid, there are two easy options: either wrap the collection in an Arc, or build druid with the im feature, which adds Data implementations to the collections from the im crate, a set of immutable data structures that fit nicely with Druid.

If the im feature is used, the im crate is reexported from the root of the druid crate.

Example:

#[derive(Clone, Data)]
struct PathEntry {
    // There's no Data impl for PathBuf, but no problem
    #[data(eq)]
    path: PathBuf,
    priority: usize,
    // This field is not part of our data model.
    #[data(ignore)]
    last_read: Instant,
}

C-style enums

In the case of a “c-style” enum (one that only contains unit variants, that is where no variant has fields), the implementation that is generated checks for equality. Therefore, such types must also implement PartialEq.

Required Methods§

fn same(&self, other: &Self) -> bool

Determine whether two values are the same.

This is intended to always be a fast operation. If it returns true, the two values must be equal, but two equal values need not be considered the same here, as will often be the case when two copies are separately allocated.

Note that “equal” above has a slightly different meaning than PartialEq, for example two floating point NaN values should be considered equal when they have the same bit representation.

Implementations on Foreign Types§

§

impl Data for SystemTime

§

fn same(&self, other: &SystemTime) -> bool

§

impl Data for i8

§

fn same(&self, other: &i8) -> bool

§

impl Data for i32

§

fn same(&self, other: &i32) -> bool

§

impl Data for i16

§

fn same(&self, other: &i16) -> bool

§

impl<T> Data for Weak<T>where T: 'static + ?Sized,

§

fn same(&self, other: &Weak<T>) -> bool

§

impl<T0, T1, T2, T3, T4, T5> Data for (T0, T1, T2, T3, T4, T5)where T0: Data, T1: Data, T2: Data, T3: Data, T4: Data, T5: Data,

§

fn same(&self, other: &(T0, T1, T2, T3, T4, T5)) -> bool

§

impl<T0, T1, T2, T3, T4> Data for (T0, T1, T2, T3, T4)where T0: Data, T1: Data, T2: Data, T3: Data, T4: Data,

§

fn same(&self, other: &(T0, T1, T2, T3, T4)) -> bool

§

impl Data for &'static str

§

fn same(&self, other: &&'static str) -> bool

§

impl Data for ()

§

fn same(&self, _other: &()) -> bool

§

impl Data for u64

§

fn same(&self, other: &u64) -> bool

§

impl Data for f64

§

fn same(&self, other: &f64) -> bool

§

impl<T0, T1> Data for (T0, T1)where T0: Data, T1: Data,

§

fn same(&self, other: &(T0, T1)) -> bool

§

impl Data for u128

§

fn same(&self, other: &u128) -> bool

§

impl Data for bool

§

fn same(&self, other: &bool) -> bool

§

impl<T0> Data for (T0,)where T0: Data,

§

fn same(&self, other: &(T0,)) -> bool

§

impl<T0, T1, T2, T3> Data for (T0, T1, T2, T3)where T0: Data, T1: Data, T2: Data, T3: Data,

§

fn same(&self, other: &(T0, T1, T2, T3)) -> bool

§

impl Data for u8

§

fn same(&self, other: &u8) -> bool

§

impl Data for f32

§

fn same(&self, other: &f32) -> bool

§

impl Data for Instant

§

fn same(&self, other: &Instant) -> bool

§

impl Data for char

§

fn same(&self, other: &char) -> bool

§

impl Data for u16

§

fn same(&self, other: &u16) -> bool

§

impl<T> Data for Arc<T>where T: 'static + ?Sized,

Checks pointer equality. The internal value is not checked.

§

fn same(&self, other: &Arc<T>) -> bool

§

impl Data for String

§

fn same(&self, other: &String) -> bool

§

impl Data for ErrorKind

§

fn same(&self, other: &ErrorKind) -> bool

§

impl<T0, T1, T2> Data for (T0, T1, T2)where T0: Data, T1: Data, T2: Data,

§

fn same(&self, other: &(T0, T1, T2)) -> bool

§

impl Data for isize

§

fn same(&self, other: &isize) -> bool

§

impl Data for usize

§

fn same(&self, other: &usize) -> bool

§

impl<T> Data for Rc<T>where T: 'static + ?Sized,

§

fn same(&self, other: &Rc<T>) -> bool

§

impl Data for i64

§

fn same(&self, other: &i64) -> bool

§

impl Data for i128

§

fn same(&self, other: &i128) -> bool

§

impl Data for u32

§

fn same(&self, other: &u32) -> bool

§

impl<T, const N: usize> Data for [T; N]where T: Data,

§

fn same(&self, other: &[T; N]) -> bool

§

impl<T> Data for Weak<T>where T: 'static + ?Sized,

§

fn same(&self, other: &Weak<T>) -> bool

Implementors§

§

impl Data for Color

§

impl Data for Cursor

§

impl Data for FontStyle

§

impl Data for TextAlignment

§

impl Data for Value

§

impl Data for PathEl

§

impl Data for PathSeg

§

impl Data for IpAddr

§

impl Data for SocketAddr

§

impl Data for InterpolationMode

§

impl Data for Axis

§

impl Data for CrossAxisAlignment

§

impl Data for FillStrat

§

impl Data for LineBreaking

§

impl Data for MainAxisAlignment

§

impl Data for TabsEdge

§

impl Data for TabsTransition

§

impl Data for AppState

§

impl Data for titanium::desktop::gui::libdruid::kurbo::Arc

§

impl Data for BezPath

§

impl Data for Circle

§

impl Data for ConstPoint

§

impl Data for CubicBez

§

impl Data for Line

§

impl Data for QuadBez

§

impl Data for RoundedRect

§

impl Data for Ipv4Addr

§

impl Data for Ipv6Addr

§

impl Data for SocketAddrV4

§

impl Data for SocketAddrV6

§

impl Data for NonZeroI8

§

impl Data for NonZeroI16

§

impl Data for NonZeroI32

§

impl Data for NonZeroI64

§

impl Data for NonZeroI128

§

impl Data for NonZeroIsize

§

impl Data for NonZeroU8

§

impl Data for NonZeroU16

§

impl Data for NonZeroU32

§

impl Data for NonZeroU64

§

impl Data for NonZeroU128

§

impl Data for NonZeroUsize

§

impl Data for RangeFull

§

impl Data for Duration

§

impl Data for Affine

§

impl Data for Env

§

impl Data for FontDescriptor

§

impl Data for FontFamily

§

impl Data for FontWeight

§

impl Data for ImageBuf

§

impl Data for Insets

§

impl Data for Point

§

impl Data for Rect

§

impl Data for RoundedRectRadii

§

impl Data for Scale

§

impl Data for Size

§

impl Data for Vec2

§

impl Data for RichText

§

impl Data for ValidationError

§

impl Data for SvgData

§

impl<T> Data for KeyOrValue<T>where T: Data,

§

impl<T> Data for Bound<T>where T: Data,

§

impl<T> Data for Option<T>where T: Data,

§

impl<T> Data for PhantomData<T>where T: 'static + ?Sized,

§

impl<T> Data for Discriminant<T>where T: 'static,

§

impl<T> Data for ManuallyDrop<T>where T: 'static + Data + ?Sized,

§

impl<T> Data for Wrapping<T>where T: Data,

§

impl<T> Data for Range<T>where T: Data,

§

impl<T> Data for RangeFrom<T>where T: Data,

§

impl<T> Data for RangeInclusive<T>where T: Data,

§

impl<T> Data for RangeTo<T>where T: Data,

§

impl<T> Data for RangeToInclusive<T>where T: Data,

§

impl<T> Data for Key<T>where T: Data,

§

impl<T, U> Data for Result<T, U>where T: Data, U: Data,

§

impl<TP> Data for TabsState<TP>where TP: TabsPolicy + Data,