ipmail 0.1.0

Rust implementation of SP-centric decentralized instant message synchronization protocol(DIMSP)
Documentation
//! [`IPLD`](https://ipld.io/) object virtual file system.
//!
//!

use std::{future::Future, io::Result, time::SystemTime};

use libipld::Cid;

use crate::mail::MailContent;

/// Ipld fs entry
pub struct Entry {
    /// multipart object cid
    pub cid: Cid,
    /// multipart object total size in bytes
    pub length: u64,
    /// Created [`time`](SystemTime) of fs entry.
    pub created: SystemTime,
}

/// Ipld filesystem trait.
pub trait IpldFS {
    type ReadEntry<'cx>: Future<Output = Result<Entry>> + Send + Unpin + 'cx
    where
        Self: 'cx;

    type Write<'cx>: Future<Output = Result<Vec<Cid>>> + Send + Unpin + 'cx
    where
        Self: 'cx;

    type Read<'cx>: Future<Output = Result<MailContent>> + Send + Unpin + 'cx
    where
        Self: 'cx;

    type Delete<'cx>: Future<Output = Result<()>> + Send + Unpin + 'cx
    where
        Self: 'cx;

    /// Read multipart object metadata by [`cid`](Cid). returns [`NotFound`](std::io::ErrorKind::NotFound) if cid not exists.
    fn read_entry<'cx, 'a>(&'a mut self, cid: Cid) -> Self::ReadEntry<'cx>
    where
        'a: 'cx;

    /// Put multipart object into local storage and returns unlink multipart cids.
    /// # parameters
    ///
    /// - `lease` The multipart object's maximum lease for storage.
    /// - `cid` multipart object's cid, the implementation must check if the cid is a valid cid for the `mime` object
    ///
    fn write<'cx, 'a>(&'a mut self, cid: Cid, content: MailContent) -> Self::Write<'cx>
    where
        'a: 'cx;

    /// Read multipart object content, returns [`NotFound`](std::io::ErrorKind::NotFound) if cid not exists.
    fn read<'cx, 'a>(&'a mut self, cid: &'cx Cid) -> Self::Read<'cx>
    where
        'a: 'cx;

    /// Delete Ipld object from file system.
    fn delete<'cx, 'a>(&'a mut self, cid: &'cx Cid) -> Self::Delete<'cx>
    where
        'a: 'cx;
}