Trait llm_weaver::storage::TapestryChestHandler

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

    // Required methods
    fn save_tapestry_fragment<'life0, 'async_trait, TID>(
        tapestry_id: &'life0 TID,
        tapestry_fragment: TapestryFragment<T>,
        increment: bool
    ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
       where TID: 'async_trait + TapestryId,
             'life0: 'async_trait;
    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 + Debug + Clone + Send + Sync;
    fn get_tapestry<'async_trait, TID>(
        tapestry_id: TID
    ) -> Pin<Box<dyn Future<Output = Result<Option<u16>>> + Send + 'async_trait>>
       where TID: 'async_trait + TapestryId;
    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
    ) -> Pin<Box<dyn Future<Output = Result<Option<M>>> + Send + 'async_trait>>
       where TID: 'async_trait + TapestryId,
             M: 'async_trait + DeserializeOwned;
    fn delete_tapestry<'async_trait, TID>(
        tapestry_id: TID
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where TID: 'async_trait + TapestryId;
    fn delete_tapestry_fragment<'async_trait, TID>(
        tapestry_id: TID,
        instance: Option<u64>
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where TID: 'async_trait + TapestryId;
}
Expand description

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

§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.

You can see how the default TapestryChest struct implementes this trait which uses Redis as its 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<'life0, 'async_trait, TID>( tapestry_id: &'life0 TID, tapestry_fragment: TapestryFragment<T>, increment: bool ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where TID: 'async_trait + TapestryId, 'life0: 'async_trait,

Saves a tapestry fragment.

Tapestry fragments are stored incrementally, also refered to as “instances”. Each instance is identified by an integer, starting at 1 and incrementing by 1 for each new instance.

This method is executed primarily by the crate::Loom::weave function.

§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.
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 + Debug + Clone + Send + Sync,

Save tapestry metadata.

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

source

fn get_tapestry<'async_trait, TID>( tapestry_id: TID ) -> Pin<Box<dyn Future<Output = Result<Option<u16>>> + Send + 'async_trait>>
where TID: 'async_trait + TapestryId,

Retrieves the number of instances of a tapestry.

Returns None if the tapestry does not exist.

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.

source

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

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

source

fn delete_tapestry<'async_trait, TID>( tapestry_id: TID ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where TID: 'async_trait + TapestryId,

Deletes a tapestry and all its instances.

source

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

Deletes a tapestry fragment.

Object Safety§

This trait is not object safe.

Implementors§