pub trait Resolver: BaseResolver {
// Provided methods
fn resolve<'life0, 'async_trait, Q>(
&'life0 self,
query: Q,
) -> Pin<Box<dyn Future<Output = Result<TwineResolution, ResolutionError>> + Send + 'async_trait>>
where Q: 'async_trait + Into<SingleQuery> + MaybeSend,
Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn has<'life0, 'async_trait, Q>(
&'life0 self,
query: Q,
) -> Pin<Box<dyn Future<Output = Result<bool, ResolutionError>> + Send + 'async_trait>>
where Q: 'async_trait + Into<SingleQuery> + MaybeSend,
Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn resolve_latest<'life0, 'async_trait, C>(
&'life0 self,
strand: C,
) -> Pin<Box<dyn Future<Output = Result<TwineResolution, ResolutionError>> + Send + 'async_trait>>
where C: 'async_trait + AsCid + MaybeSend,
Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn resolve_index<'life0, 'async_trait, C>(
&'life0 self,
strand: C,
index: u64,
) -> Pin<Box<dyn Future<Output = Result<TwineResolution, ResolutionError>> + Send + 'async_trait>>
where C: 'async_trait + AsCid + MaybeSend,
Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn resolve_stitch<'life0, 'async_trait, C>(
&'life0 self,
strand: C,
tixel: C,
) -> Pin<Box<dyn Future<Output = Result<TwineResolution, ResolutionError>> + Send + 'async_trait>>
where C: 'async_trait + AsCid + MaybeSend,
Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn resolve_strand<'life0, 'async_trait, C>(
&'life0 self,
strand: C,
) -> Pin<Box<dyn Future<Output = Result<StrandResolution, ResolutionError>> + Send + 'async_trait>>
where C: 'async_trait + AsCid + MaybeSend,
Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
fn resolve_range<'a, 'async_trait, R>(
&'a self,
range: R,
) -> Pin<Box<dyn Future<Output = Result<TwineStream<'a, Twine>, ResolutionError>> + Send + 'async_trait>>
where R: 'async_trait + Into<RangeQuery> + MaybeSend,
Self: Sync + 'async_trait,
'a: 'async_trait { ... }
fn strands<'a, 'async_trait>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<TwineStream<'a, Strand>, ResolutionError>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'a: 'async_trait { ... }
fn latest_index<'life0, 'life1, 'async_trait>(
&'life0 self,
strand: &'life1 Cid,
) -> Pin<Box<dyn Future<Output = Result<u64, ResolutionError>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
This is a standardized interface for retrieving Twine objects
Datastores will implement this trait (indirectly through BaseResolver)
to provide a consistent interface for retrieving Twine objects.
By retrieving Twine objects through this interface, the caller can be sure that the data is consistent and verified for integrity and authenticity.
The methods of this trait accept arguments that implement the Into trait
or similar. This allows for a variety of ways of using the methods
making them more accessible and understandable.
§Example
use twine_lib::store::MemoryStore;
let some_resolver = MemoryStore::default();
let some_strand_cid: Cid = "bafyrmieej3j3sprtnbfziv6vhixzr3xxrcabnma43ajb5grhsixdvxzdvu".parse().unwrap();
// resolve the latest on the Strand
let latest = some_resolver.resolve_latest(some_strand_cid).await?;
// or do the same but use a Strand object
let strand = some_resolver.resolve_strand(some_strand_cid).await?.unpack();
let latest = some_resolver.resolve_latest(&strand).await?;
// resolve the 31st Tixel on the Strand
let thirty_first = some_resolver.resolve_index(some_strand_cid, 31).await?;
// or use an argument that implements Into<Query> like a tuple
let thirty_first = some_resolver.resolve((some_strand_cid, 31)).await?;
// or parse a Query from a string
let query: SingleQuery = "bafyrmieej3j3sprtnbfziv6vhixzr3xxrcabnma43ajb5grhsixdvxzdvu:31".parse().unwrap();
let thirty_first = some_resolver.resolve(query).await?;
// resolve a stitch
let linked = thirty_first.cross_stitches();
let some_other_twine = some_resolver.resolve(linked.stitches().get(0).unwrap().clone()).await?;Provided Methods§
Sourcefn resolve<'life0, 'async_trait, Q>(
&'life0 self,
query: Q,
) -> Pin<Box<dyn Future<Output = Result<TwineResolution, ResolutionError>> + Send + 'async_trait>>where
Q: 'async_trait + Into<SingleQuery> + MaybeSend,
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn resolve<'life0, 'async_trait, Q>(
&'life0 self,
query: Q,
) -> Pin<Box<dyn Future<Output = Result<TwineResolution, ResolutionError>> + Send + 'async_trait>>where
Q: 'async_trait + Into<SingleQuery> + MaybeSend,
Self: Sync + 'async_trait,
'life0: 'async_trait,
Resolve a Twine object from a query
§Example
use twine_lib::store::MemoryStore;
let some_storage = MemoryStore::default();
// ...
let thirty_first = some_storage.resolve((strand_cid, 31)).await?;Sourcefn has<'life0, 'async_trait, Q>(
&'life0 self,
query: Q,
) -> Pin<Box<dyn Future<Output = Result<bool, ResolutionError>> + Send + 'async_trait>>where
Q: 'async_trait + Into<SingleQuery> + MaybeSend,
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn has<'life0, 'async_trait, Q>(
&'life0 self,
query: Q,
) -> Pin<Box<dyn Future<Output = Result<bool, ResolutionError>> + Send + 'async_trait>>where
Q: 'async_trait + Into<SingleQuery> + MaybeSend,
Self: Sync + 'async_trait,
'life0: 'async_trait,
Check if a Twine is available for a given query
Sourcefn resolve_latest<'life0, 'async_trait, C>(
&'life0 self,
strand: C,
) -> Pin<Box<dyn Future<Output = Result<TwineResolution, ResolutionError>> + Send + 'async_trait>>
fn resolve_latest<'life0, 'async_trait, C>( &'life0 self, strand: C, ) -> Pin<Box<dyn Future<Output = Result<TwineResolution, ResolutionError>> + Send + 'async_trait>>
Resolve the Twine data with the highest index for a given Strand
Sourcefn resolve_index<'life0, 'async_trait, C>(
&'life0 self,
strand: C,
index: u64,
) -> Pin<Box<dyn Future<Output = Result<TwineResolution, ResolutionError>> + Send + 'async_trait>>
fn resolve_index<'life0, 'async_trait, C>( &'life0 self, strand: C, index: u64, ) -> Pin<Box<dyn Future<Output = Result<TwineResolution, ResolutionError>> + Send + 'async_trait>>
Resolve a Twine object by its index on a Strand
Sourcefn resolve_stitch<'life0, 'async_trait, C>(
&'life0 self,
strand: C,
tixel: C,
) -> Pin<Box<dyn Future<Output = Result<TwineResolution, ResolutionError>> + Send + 'async_trait>>
fn resolve_stitch<'life0, 'async_trait, C>( &'life0 self, strand: C, tixel: C, ) -> Pin<Box<dyn Future<Output = Result<TwineResolution, ResolutionError>> + Send + 'async_trait>>
Resolve a Twine object by a Stitch (a Strand CID and a Tixel CID)
§Example
tokio::runtime::Runtime::new().unwrap().block_on(async {
let strand_cid: Cid = "bafyrmieej3j3sprtnbfziv6vhixzr3xxrcabnma43ajb5grhsixdvxzdvu".parse().unwrap();
let tixel_cid: Cid = "bafyriqgafbhhudahpnzrdvuzjjczro43i4mnv7637vq4oh6m6lfdccpazmmurfu4vluy7iddrhwbbfvjs62uo2wrzx4axaxx5lv7pfmqveqt2".parse().unwrap();
let twine = resolver.resolve_stitch(strand_cid, tixel_cid).await?;
Ok::<_, ResolutionError>(())Sourcefn resolve_strand<'life0, 'async_trait, C>(
&'life0 self,
strand: C,
) -> Pin<Box<dyn Future<Output = Result<StrandResolution, ResolutionError>> + Send + 'async_trait>>
fn resolve_strand<'life0, 'async_trait, C>( &'life0 self, strand: C, ) -> Pin<Box<dyn Future<Output = Result<StrandResolution, ResolutionError>> + Send + 'async_trait>>
Resolve a Strand object by its CID
§Example
tokio::runtime::Runtime::new().unwrap().block_on(async {
let cid: Cid = "bafyrmieej3j3sprtnbfziv6vhixzr3xxrcabnma43ajb5grhsixdvxzdvu".parse().unwrap();
let latest = resolver.resolve_latest(cid).await?;Sourcefn resolve_range<'a, 'async_trait, R>(
&'a self,
range: R,
) -> Pin<Box<dyn Future<Output = Result<TwineStream<'a, Twine>, ResolutionError>> + Send + 'async_trait>>
fn resolve_range<'a, 'async_trait, R>( &'a self, range: R, ) -> Pin<Box<dyn Future<Output = Result<TwineStream<'a, Twine>, ResolutionError>> + Send + 'async_trait>>
Resolve a range of Twine objects on a Strand
This can be supplied as a RangeQuery or any type that implements Into<RangeQuery>
§Example
let cid_strand: Cid = "bafyrmieej3j3sprtnbfziv6vhixzr3xxrcabnma43ajb5grhsixdvxzdvu".parse().unwrap();
// resolve the first 11 (because ranges are inclusive) Tixels on the Strand
let stream = resolver.resolve_range((cid_strand, 0, 10)).await?;
// dump them into a Vec
use futures::stream::TryStreamExt;
let records: Vec<Twine> = stream.try_collect().await?;Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.