pub async fn create_backend(
backend_type: BackendType,
config: BackendConfig,
) -> Result<Box<dyn StorageBackend>, IncrementalError>Expand description
Creates a storage backend based on the specified type and configuration.
This factory function provides runtime backend selection with compile-time
feature gating. If a backend is requested but its feature flag is disabled,
returns IncrementalError::UnsupportedBackend.
§Arguments
backend_type- The type of backend to instantiate.config- Configuration parameters for the backend.
§Returns
A boxed trait object implementing StorageBackend, or an error if:
- The backend feature is disabled (
IncrementalError::UnsupportedBackend) - Backend initialization fails (
IncrementalError::InitializationFailed) - Configuration mismatch between
backend_typeandconfig
§Examples
use thread_flow::incremental::backends::{BackendType, BackendConfig, create_backend};
// Create in-memory backend (always available)
let backend = create_backend(
BackendType::InMemory,
BackendConfig::InMemory,
).await?;
// Create Postgres backend (requires postgres-backend feature)
let backend = create_backend(
BackendType::Postgres,
BackendConfig::Postgres {
database_url: "postgresql://localhost/thread".to_string(),
},
).await?;§Errors
IncrementalError::UnsupportedBackend: Feature flag disabled for requested backendIncrementalError::InitializationFailed: Connection failed, invalid config, or initialization error