pub struct GenericMessagePersistenceManagerBuilder<T: MessagesManagerTrait> {
storage: Option<Arc<dyn MessageStorage>>,
relay_id: Option<KeyId>,
buffer_size: Option<usize>,
autosubscribe: bool,
_phantom: PhantomData<T>,
}Expand description
Builder for creating MessagePersistenceManager instances.
This builder allows configuring persistence behavior and connecting to existing MessageStorage and MessagesManager instances via references.
§Example
// Create persistence manager with embedded MessagesManager
let persistence_manager = MessagePersistenceManagerBuilder::new()
.storage(storage)
.autosubscribe(true)
.relay_pubkey(relay_key)
.buffer_size(1000)
.build(connection)
.await?;
// Access MessagesManager via Deref
let _stream = persistence_manager.subscribe_to_messages().await?;
// Or access explicitly for better discoverability
let messages_manager = persistence_manager.messages_manager();
let _stream = messages_manager.subscribe_to_messages().await?;Fields§
§storage: Option<Arc<dyn MessageStorage>>§relay_id: Option<KeyId>§buffer_size: Option<usize>§autosubscribe: bool§_phantom: PhantomData<T>Implementations§
Source§impl<T: MessagesManagerTrait> GenericMessagePersistenceManagerBuilder<T>
impl<T: MessagesManagerTrait> GenericMessagePersistenceManagerBuilder<T>
Sourcepub fn storage(self, storage: Arc<dyn MessageStorage>) -> Self
pub fn storage(self, storage: Arc<dyn MessageStorage>) -> Self
Set the storage implementation to use for persistence
Sourcepub fn autosubscribe(self, autosubscribe: bool) -> Self
pub fn autosubscribe(self, autosubscribe: bool) -> Self
Set whether to automatically subscribe after creating the messages manager
Sourcepub fn relay_id(self, relay_id: KeyId) -> Self
pub fn relay_id(self, relay_id: KeyId) -> Self
Set the relay ID (hash of public key) for sync tracking
Sourcepub fn relay_pubkey(self, relay_pubkey: VerifyingKey) -> Self
pub fn relay_pubkey(self, relay_pubkey: VerifyingKey) -> Self
Set the relay public key for sync tracking (convenience method that computes the ID)
Sourcepub fn buffer_size(self, buffer_size: usize) -> Self
pub fn buffer_size(self, buffer_size: usize) -> Self
Set the buffer size for the persistence task queue
pub async fn build_with_messages_manager( self, messages_manager: Arc<T>, ) -> Result<GenericMessagePersistenceManager<T>>
Source§impl GenericMessagePersistenceManagerBuilder<MessagesManager>
impl GenericMessagePersistenceManagerBuilder<MessagesManager>
Sourcepub async fn build_with_messages_manager_configuration<F>(
self,
connection: &Connection,
configure: F,
) -> Result<MessagePersistenceManager>
pub async fn build_with_messages_manager_configuration<F>( self, connection: &Connection, configure: F, ) -> Result<MessagePersistenceManager>
Build the MessagePersistenceManager and MessagesManager
This will:
- Create the MessagesManager from the connection and configuration
- Create the MessagePersistenceManager with the MessagesManager
- Start the background persistence task
- Return a fully configured MessagePersistenceManager
§Errors
Returns an error if storage is not provided or connection fails
Sourcepub async fn build(
self,
connection: &Connection,
) -> Result<MessagePersistenceManager>
pub async fn build( self, connection: &Connection, ) -> Result<MessagePersistenceManager>
Build the MessagePersistenceManager and MessagesManager
This will:
- Create the MessagesManager from the connection and configuration
- Create the MessagePersistenceManager with the MessagesManager
- Start the background persistence task
- Return a fully configured MessagePersistenceManager
§Errors
Returns an error if storage is not provided or connection fails