ladata/unit/traits.rs
1// ladata::unit::traits
2//
3//! The traits for unitary data.
4//
5// - DataType
6// - DataTypeCopy
7// - DataUnit
8// - DataUnitCopy
9// - DataRaw
10
11use core::fmt::Debug;
12
13/// Common trait for *data types*.
14///
15/// Allows extending `DataType*`**`With`** versions with custom *types*.
16///
17/// # See also
18/// - [`DataTypeCopy`]
19/// - [`DataUnitCopy`]
20/// - [`DataUnit`]
21pub trait DataType: Copy + Debug {
22 /// Returns the alignment of the data represented by the current type.
23 fn data_align(&self) -> usize;
24
25 /// Returns the size of the data represented by this type.
26 fn data_size(&self) -> usize;
27
28 /// Returns true if the data represented by this type is [`Copy`].
29 fn is_copy(&self) -> bool;
30}
31
32/// Common (marker) trait for `Copy` *data types*.
33///
34/// Allows extending `DataType*Copy`**`With`** versions with custom *types*.
35///
36/// # Coherence
37///
38/// The `DataType::`[`is_copy`][DataType#method.is_copy]
39/// super-trait method should probably return `true` as well.
40///
41/// # See also
42/// - [`DataType`]
43/// - [`DataUnit`]
44/// - [`DataUnitCopy`]
45pub trait DataTypeCopy: DataType {}
46
47/// Common trait for *data units*.
48///
49/// Allows extending `DataUnit*`**`With`** versions.
50///
51/// See also:
52/// - [`DataUnitCopy`]
53/// - [`DataTypeCopy`]
54/// - [`DataType`]
55pub trait DataUnit: Debug {
56 /// Whether the data type in the current variant is [`Copy`].
57 fn is_copy(&self) -> bool;
58}
59
60/// Common (marker) trait for `Copy` *data units*.
61///
62/// Allows extending `DataUnit*Copy`**`With`** versions.
63///
64/// # Coherence
65///
66/// The `DataUnit::`[`is_copy`][DataUnit#method.is_copy]
67/// super-trait method should probably return `true` as well.
68///
69/// # See also
70/// - [`DataUnit`]
71/// - [`DataType`]
72/// - [`DataTypeCopy`]
73pub trait DataUnitCopy: DataUnit + Copy {}
74
75/// Common trait for *unsafe data units*.
76///
77/// # Safety
78/// TODO
79///
80#[cfg(feature = "unsafe_unit")]
81#[cfg_attr(feature = "nightly", doc(cfg(feature = "not(safe)")))]
82pub unsafe trait DataRaw {}
83
84/// Comon (marker) trait for *unsafe* `Copy` *data units*.
85///
86/// # Safety
87/// TODO
88///
89#[cfg(feature = "unsafe_unit")]
90#[cfg_attr(feature = "nightly", doc(cfg(feature = "not(safe)")))]
91pub unsafe trait DataRawCopy: DataRaw + Copy {}