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§
Sourcetype Transport: SyncTransport
type Transport: SyncTransport
The transport type this builder creates.