intrepid-model 0.2.0

Manage complex async business logic with ease
Documentation
use super::{Cache, CacheRecord, IntoCache};

/// An error that can occur when interacting with a cache repository.
#[derive(Debug, thiserror::Error)]
pub enum CacheRepoError {
    /// Unable to insert a cache record
    #[error("Unable to set cache record")]
    SetFailed,
}

/// The trait for a cache repository. Implement this trait to provide a cache
/// repository interface for any given cache implementation.
#[async_trait::async_trait]
pub trait CacheRepo {
    /// Get a memo by URI
    async fn get_memo(
        &self,
        uri: impl AsRef<str> + Send,
    ) -> Result<Cache<CacheRecord>, CacheRepoError>;

    /// Set a memo with any type that implements [`IntoCache`]
    async fn set_memo<CacheCandidate>(
        &self,
        record: CacheCandidate,
    ) -> Result<CacheRecord, CacheRepoError>
    where
        CacheCandidate: IntoCache + Send;
}