pub trait TapestryChestHandler<T: Config> {
    type Error: Display + Debug;

    // Required methods
    fn save_tapestry_fragment<'async_trait, TID>(
        tapestry_id: TID,
        tapestry_fragment: TapestryFragment<T>,
        increment: bool
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where TID: 'async_trait + TapestryId;
    fn save_tapestry_metadata<'async_trait, TID, M>(
        tapestry_id: TID,
        metadata: M
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where TID: 'async_trait + TapestryId,
             M: 'async_trait + ToRedisArgs + Send + Sync;
    fn get_tapestry_fragment<'async_trait, TID>(
        tapestry_id: TID,
        instance: Option<u64>
    ) -> Pin<Box<dyn Future<Output = Result<Option<TapestryFragment<T>>>> + Send + 'async_trait>>
       where TID: 'async_trait + TapestryId;
    fn get_tapestry_metadata<'async_trait, TID, M>(
        tapestry_id: TID,
        instance: Option<u64>
    ) -> Pin<Box<dyn Future<Output = Result<Option<M>>> + Send + 'async_trait>>
       where TID: 'async_trait + TapestryId,
             M: 'async_trait + DeserializeOwned + Default;
}
Expand description

A storage handler trait designed for saving and retrieving fragments of a tapestry.

The TapestryChestHandler trait provides an asynchronous interface for implementing various storage handlers to manage tapestry fragments.

Usage

Implementations of TapestryChestHandler should provide the storage and retrieval mechanisms tailored to specific use-cases or storage backends, such as databases, file systems, or in-memory stores.

Checkout the out of the box implementation TapestryChest whichs uses Redis as the storage backend.

Required Associated Types§

source

type Error: Display + Debug

Defines the error type returned by the handler methods.

Required Methods§

source

fn save_tapestry_fragment<'async_trait, TID>( tapestry_id: TID, tapestry_fragment: TapestryFragment<T>, increment: bool ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where TID: 'async_trait + TapestryId,

Saves a tapestry fragment.

Parameters
  • tapestry_id: Identifies the tapestry.
  • tapestry_fragment: An instance of TapestryFragment to be stored.
  • increment:
    • A boolean flag indicating whether the tapestry instance should be incremented.
    • This should typically be true when saving a new instance of TapestryFragment, and false when updating an existing one.
Returns

Returns Result<(), Self::Error>. On successful storage, it returns Ok(()). If the storage operation fails, it should return an Err variant containing an error of type Self::Error.

source

fn save_tapestry_metadata<'async_trait, TID, M>( tapestry_id: TID, metadata: M ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where TID: 'async_trait + TapestryId, M: 'async_trait + ToRedisArgs + Send + Sync,

Save tapestry metadata.

Based on application use cases, you can add aditional data for a given TapestryId

source

fn get_tapestry_fragment<'async_trait, TID>( tapestry_id: TID, instance: Option<u64> ) -> Pin<Box<dyn Future<Output = Result<Option<TapestryFragment<T>>>> + Send + 'async_trait>>where TID: 'async_trait + TapestryId,

Retrieves the last tapestry fragment, or a fragment at a specified instance.

Parameters
  • tapestry_id: Identifies the tapestry.
  • instance: The instance of the fragment to retrieve. If None, the method should retrieve the last fragment.
Returns

On successful retrieval, it returns Ok(Some(TapestryFragment)) or Ok(None) if no fragment was found. If the retrieval operation fails, it should return an Err variant containing an error of type Self::Error.

source

fn get_tapestry_metadata<'async_trait, TID, M>( tapestry_id: TID, instance: Option<u64> ) -> Pin<Box<dyn Future<Output = Result<Option<M>>> + Send + 'async_trait>>where TID: 'async_trait + TapestryId, M: 'async_trait + DeserializeOwned + Default,

Retrieves the last tapestry metadata, or a metadata at a specified instance.

Object Safety§

This trait is not object safe.

Implementors§