Skip to main content

RootResolver

Trait RootResolver 

Source
pub trait RootResolver: Send + Sync {
    // Required methods
    fn resolve<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Cid>, ResolverError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn subscribe<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Receiver<Option<Cid>>, ResolverError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn resolve_shared<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        share_secret: &'life2 [u8; 32],
    ) -> Pin<Box<dyn Future<Output = Result<Option<Cid>, ResolverError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait { ... }
    fn publish<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        cid: &'life2 Cid,
    ) -> Pin<Box<dyn Future<Output = Result<bool, ResolverError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait { ... }
    fn publish_shared<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        cid: &'life2 Cid,
        share_secret: &'life3 [u8; 32],
    ) -> Pin<Box<dyn Future<Output = Result<bool, ResolverError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             Self: 'async_trait { ... }
    fn list<'life0, 'life1, 'async_trait>(
        &'life0 self,
        prefix: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<ResolverEntry>, ResolverError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
    fn subscribe_list<'life0, 'life1, 'async_trait>(
        &'life0 self,
        prefix: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Receiver<Vec<ResolverEntry>>, ResolverError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
    fn stop<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), ResolverError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
}
Expand description

RootResolver - Maps human-readable keys to content identifiers (Cid)

Implement this trait to provide mutable pointers to immutable content-addressed data. The optional nostr feature supplies a Nostr backend.

The Cid contains:

  • hash: content hash (always present)
  • key: optional decryption key (for CHK encrypted content)

Unlike the TypeScript version which uses callbacks, this Rust version uses channels which are more idiomatic for async Rust.

Required Methods§

Source

fn resolve<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Cid>, ResolverError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Resolve a key to its current Cid (one-shot)

Returns None if no usable root was found in this lookup. This is not proof of absence on a network. For shared content, use resolve_shared.

Source

fn subscribe<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Receiver<Option<Cid>>, ResolverError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Subscribe to Cid changes for a key.

Returns a channel receiver that will receive the current value immediately, then subsequent updates. The channel is closed when the subscription ends.

To unsubscribe, simply drop the receiver.

Provided Methods§

Source

fn resolve_shared<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, share_secret: &'life2 [u8; 32], ) -> Pin<Box<dyn Future<Output = Result<Option<Cid>, ResolverError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Resolve with a share secret (for encrypted_key decryption)

Source

fn publish<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, cid: &'life2 Cid, ) -> Pin<Box<dyn Future<Output = Result<bool, ResolverError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Publish/update a Cid (optional - only for writable backends)

Returns true if published successfully.

Source

fn publish_shared<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, key: &'life1 str, cid: &'life2 Cid, share_secret: &'life3 [u8; 32], ) -> Pin<Box<dyn Future<Output = Result<bool, ResolverError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, Self: 'async_trait,

Publish with encrypted key for sharing

The key is encrypted with share_secret, allowing anyone with the secret to decrypt.

Source

fn list<'life0, 'life1, 'async_trait>( &'life0 self, prefix: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<ResolverEntry>, ResolverError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

List all keys matching a prefix (one-shot)

Returns array of matching keys with their current Cids.

Source

fn subscribe_list<'life0, 'life1, 'async_trait>( &'life0 self, prefix: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Receiver<Vec<ResolverEntry>>, ResolverError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Subscribe to list changes for a prefix.

Returns a channel receiver that will receive the current list immediately, then the full updated list on each add/remove/update.

Source

fn stop<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), ResolverError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Stop the resolver and clean up resources

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§