veecle_os_runtime/datastore/slot/
storable.rs

1use core::fmt::Debug;
2
3/// Marks a type as an identifier for the inner `DataType`, which can be transferred via a slot.
4///
5/// # Usage
6///
7/// The trait allows separating the data type from the identifier type.
8/// This allows registering multiple data type of the same type with unique identifiers, avoiding collisions.
9///
10/// This trait can be derived via the [`Storable`][derive@crate::datastore::Storable] derive macro,
11/// see its documentation for more details.
12///
13/// ```
14/// use veecle_os_runtime::Storable;
15///
16/// // Identifier type.
17/// #[derive(Debug, Default)]
18/// struct Sensor;
19///
20/// impl Storable for Sensor {
21///     // Data type.
22///     type DataType = u8;
23/// }
24/// ```
25///
26/// If the data type is unique and should be used as the identifier, the data type can be set to `Self`.
27/// ```
28/// use veecle_os_runtime::Storable;
29///
30/// // Identifier type.
31/// #[derive(Debug, Default)]
32/// struct Sensor{
33///     // ...
34/// };
35///
36/// impl Storable for Sensor {
37///     // Data type.
38///     type DataType = Self;
39/// }
40/// ```
41pub trait Storable {
42    /// The data type being read/written from/to a slot.
43    type DataType: Debug;
44}