1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//! Raw access to underlying storage.
//!
//! This can be useful to implement more efficient serialization, since it might
//! provide access to smaller primitive values.

/// Trait implemented for storage which can be easily converted to and from a
/// raw value.
///
/// This is implemented for [`SetStorage`] which is generated from
/// `#[key(bitset)]`.
///
/// [`SetStorage`]: crate::set::SetStorage
pub trait RawStorage: Sized {
    /// The backing raw value.
    type Value;

    /// Get the raw value of the storage.
    fn as_raw(&self) -> Self::Value;

    /// Build storage from raw storage.
    fn from_raw(raw: Self::Value) -> Self;
}