Trait llm_weaver::storage::TapestryChestHandler
source · pub trait TapestryChestHandler<T: Config> {
type Error: Display + Debug;
// Required methods
fn new() -> Self;
fn save_tapestry_fragment<'life0, 'life1, 'async_trait, TID>(
&'life0 self,
tapestry_id: &'life1 TID,
tapestry_fragment: TapestryFragment<T>,
increment: bool,
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where TID: 'async_trait + TapestryId,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn save_tapestry_metadata<'life0, 'async_trait, TID, M>(
&'life0 self,
tapestry_id: TID,
metadata: M,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where TID: 'async_trait + TapestryId,
M: 'async_trait + Serialize + Debug + Clone + Send + Sync,
Self: 'async_trait,
'life0: 'async_trait;
fn get_instance_index<'life0, 'async_trait, TID>(
&'life0 self,
tapestry_id: TID,
) -> Pin<Box<dyn Future<Output = Result<Option<u16>>> + Send + 'async_trait>>
where TID: 'async_trait + TapestryId,
Self: 'async_trait,
'life0: 'async_trait;
fn get_tapestry_fragment<'life0, 'async_trait, TID>(
&'life0 self,
tapestry_id: TID,
instance: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<Option<TapestryFragment<T>>>> + Send + 'async_trait>>
where TID: 'async_trait + TapestryId,
Self: 'async_trait,
'life0: 'async_trait;
fn get_tapestry_metadata<'life0, 'async_trait, TID, M>(
&'life0 self,
tapestry_id: TID,
) -> Pin<Box<dyn Future<Output = Result<Option<M>>> + Send + 'async_trait>>
where TID: 'async_trait + TapestryId,
M: 'async_trait + DeserializeOwned + Send + Sync,
Self: 'async_trait,
'life0: 'async_trait;
fn delete_tapestry<'life0, 'async_trait, TID>(
&'life0 self,
tapestry_id: TID,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where TID: 'async_trait + TapestryId,
Self: 'async_trait,
'life0: 'async_trait;
fn delete_tapestry_fragment<'life0, 'async_trait, TID>(
&'life0 self,
tapestry_id: TID,
instance: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where TID: 'async_trait + TapestryId,
Self: 'async_trait,
'life0: 'async_trait;
}
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.
Required Associated Types§
Required Methods§
fn new() -> Self
sourcefn save_tapestry_fragment<'life0, 'life1, 'async_trait, TID>(
&'life0 self,
tapestry_id: &'life1 TID,
tapestry_fragment: TapestryFragment<T>,
increment: bool,
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>where
TID: 'async_trait + TapestryId,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn save_tapestry_fragment<'life0, 'life1, 'async_trait, TID>(
&'life0 self,
tapestry_id: &'life1 TID,
tapestry_fragment: TapestryFragment<T>,
increment: bool,
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>where
TID: 'async_trait + TapestryId,
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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 ofTapestryFragment
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 ofTapestryFragment
, andfalse
when updating an existing one.
sourcefn save_tapestry_metadata<'life0, 'async_trait, TID, M>(
&'life0 self,
tapestry_id: TID,
metadata: M,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
fn save_tapestry_metadata<'life0, 'async_trait, TID, M>( &'life0 self, tapestry_id: TID, metadata: M, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
Save tapestry metadata.
Based on application use cases, you can add aditional data for a given TapestryId
sourcefn get_instance_index<'life0, 'async_trait, TID>(
&'life0 self,
tapestry_id: TID,
) -> Pin<Box<dyn Future<Output = Result<Option<u16>>> + Send + 'async_trait>>where
TID: 'async_trait + TapestryId,
Self: 'async_trait,
'life0: 'async_trait,
fn get_instance_index<'life0, 'async_trait, TID>(
&'life0 self,
tapestry_id: TID,
) -> Pin<Box<dyn Future<Output = Result<Option<u16>>> + Send + 'async_trait>>where
TID: 'async_trait + TapestryId,
Self: 'async_trait,
'life0: 'async_trait,
Retrieves the index of a tapestry.
Returns None if the tapestry does not exist.
sourcefn get_tapestry_fragment<'life0, 'async_trait, TID>(
&'life0 self,
tapestry_id: TID,
instance: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<Option<TapestryFragment<T>>>> + Send + 'async_trait>>where
TID: 'async_trait + TapestryId,
Self: 'async_trait,
'life0: 'async_trait,
fn get_tapestry_fragment<'life0, 'async_trait, TID>(
&'life0 self,
tapestry_id: TID,
instance: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<Option<TapestryFragment<T>>>> + Send + 'async_trait>>where
TID: 'async_trait + TapestryId,
Self: 'async_trait,
'life0: 'async_trait,
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. IfNone
, the method should retrieve the last fragment.
§Returns
On successful retrieval, it returns Ok(Some(TapestryFragment))
or Ok(None)
if no
fragment was found.
sourcefn get_tapestry_metadata<'life0, 'async_trait, TID, M>(
&'life0 self,
tapestry_id: TID,
) -> Pin<Box<dyn Future<Output = Result<Option<M>>> + Send + 'async_trait>>where
TID: 'async_trait + TapestryId,
M: 'async_trait + DeserializeOwned + Send + Sync,
Self: 'async_trait,
'life0: 'async_trait,
fn get_tapestry_metadata<'life0, 'async_trait, TID, M>(
&'life0 self,
tapestry_id: TID,
) -> Pin<Box<dyn Future<Output = Result<Option<M>>> + Send + 'async_trait>>where
TID: 'async_trait + TapestryId,
M: 'async_trait + DeserializeOwned + Send + Sync,
Self: 'async_trait,
'life0: 'async_trait,
Retrieves the last tapestry metadata, or a metadata at a specified instance.
sourcefn delete_tapestry<'life0, 'async_trait, TID>(
&'life0 self,
tapestry_id: TID,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
TID: 'async_trait + TapestryId,
Self: 'async_trait,
'life0: 'async_trait,
fn delete_tapestry<'life0, 'async_trait, TID>(
&'life0 self,
tapestry_id: TID,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
TID: 'async_trait + TapestryId,
Self: 'async_trait,
'life0: 'async_trait,
Deletes a tapestry and all its instances.