oml-storage 0.1.5-alpha

A very simple wrapper to handle locked storage of items.
Documentation
use async_trait::async_trait;
use color_eyre::eyre::Result;

/// The `trait` your items need to implement to be storable
///
/// If your item is serialisable and deserialisable via serde you can use something like:
/// ```
/// impl StorageItem for TestItem {
///     fn serialize(&self) -> Result<Vec<u8>> {
///         let json = serde_json::to_string_pretty(&self)?;
///     
///         Ok(json.into())
///     }
///     fn deserialize(data: &[u8]) -> Result<Self>
///     where
///         Self: Sized,
///     {
///         let i = serde_json::from_slice(&data)?;
///     
///         Ok(i)
///     }
/// }
/// ```
///

#[async_trait]
pub trait StorageItem: core::fmt::Debug + std::default::Default + std::marker::Sync {
    fn serialize(&self) -> Result<Vec<u8>>;
    fn deserialize(data: &[u8]) -> Result<Self>
    where
        Self: Sized;
}