Development Documentation (main branch) - For stable release docs, see docs.rs/eidetica

TransportBuilder

Trait TransportBuilder 

Source
pub trait TransportBuilder: Send {
    type Transport: SyncTransport;

    // Required method
    fn build<'async_trait>(
        self,
        persisted: Doc,
    ) -> Pin<Box<dyn Future<Output = Result<(Self::Transport, Option<Doc>)>> + Send + 'async_trait>>
       where Self: 'async_trait;
}
Expand description

Builder for creating transports with persisted state.

Each transport implementation should provide a builder that implements this trait. The builder configures the transport, and the build() method creates the transport using persisted state (loaded by name from the sync database).

§Persisted State

Each named transport instance has its own persisted Doc that stores state that should survive restarts (e.g., cryptographic keys for identity). The build() method receives this state and can update it (e.g., generating a new key on first run). The updated state is saved after the transport is created.

§Example

use async_trait::async_trait;
use eidetica::{Result, crdt::Doc};
use eidetica::sync::transports::{TransportBuilder, SyncTransport};

pub struct MyTransportBuilder {
    pub some_setting: String,
}

#[async_trait]
impl TransportBuilder for MyTransportBuilder {
    type Transport = MyTransport;

    async fn build(self, persisted: Doc) -> Result<(Self::Transport, Option<Doc>)> {
        let transport = MyTransport::new(self.some_setting);
        Ok((transport, None)) // No state to persist
    }
}

Required Associated Types§

Source

type Transport: SyncTransport

The transport type this builder creates.

Required Methods§

Source

fn build<'async_trait>( self, persisted: Doc, ) -> Pin<Box<dyn Future<Output = Result<(Self::Transport, Option<Doc>)>> + Send + 'async_trait>>
where Self: 'async_trait,

Build the transport from persisted state.

§Arguments
  • persisted - The persisted state for this named transport instance. May be empty on first run.
§Returns

A tuple of (transport, optional_updated_state). If Some(doc), the state will be saved to the sync database. If None, no save is performed.

Implementors§