pub struct StateRegistry {
sdk_managed: RwLock<Vec<RepositoryItemData>>,
client_managed: RwLock<HashMap<TypeId, Box<dyn Any + Send + Sync>>>,
database: OnceLock<SqliteDatabase>,
}Expand description
A registry that contains repositories for different types of items. These repositories can be either managed by the client or by the SDK itself.
Fields§
§sdk_managed: RwLock<Vec<RepositoryItemData>>§client_managed: RwLock<HashMap<TypeId, Box<dyn Any + Send + Sync>>>§database: OnceLock<SqliteDatabase>Implementations§
Source§impl StateRegistry
impl StateRegistry
Sourcepub async fn initialize_database(
&self,
configuration: DatabaseConfiguration,
migrations: RepositoryMigrations,
) -> Result<(), StateRegistryError>
pub async fn initialize_database( &self, configuration: DatabaseConfiguration, migrations: RepositoryMigrations, ) -> Result<(), StateRegistryError>
Initializes the database used for sdk-managed repositories.
Sourcepub fn register_client_managed<T: RepositoryItem>(
&self,
value: Arc<dyn Repository<T>>,
)
pub fn register_client_managed<T: RepositoryItem>( &self, value: Arc<dyn Repository<T>>, )
Registers a client-managed repository into the map, associating it with its type.
Sourcefn get_client_managed<T: RepositoryItem>(
&self,
) -> Option<Arc<dyn Repository<T>>>
fn get_client_managed<T: RepositoryItem>( &self, ) -> Option<Arc<dyn Repository<T>>>
Retrieves a client-managed repository from the map given its type.
Sourcefn get_sdk_managed<T: RepositoryItem>(
&self,
) -> Result<Arc<dyn Repository<T>>, StateRegistryError>
fn get_sdk_managed<T: RepositoryItem>( &self, ) -> Result<Arc<dyn Repository<T>>, StateRegistryError>
Retrieves a SDK-managed repository from the database.
Sourcepub fn get<T>(&self) -> Result<Arc<dyn Repository<T>>, StateRegistryError>where
T: RepositoryItem,
pub fn get<T>(&self) -> Result<Arc<dyn Repository<T>>, StateRegistryError>where
T: RepositoryItem,
Get a repository with fallback: prefer client-managed, fall back to SDK-managed.
This method first attempts to retrieve a client-managed repository. If not found,
it falls back to an SDK-managed repository. Both are returned as Arc<dyn Repository<T>>.
§Type Requirements
Tmust implementRepositoryItem(for both types)
§Errors
Returns StateRegistryError when:
- Client-managed repository is not registered, AND
- SDK-managed repository cannot be retrieved (e.g., database not initialized)
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for StateRegistry
impl !RefUnwindSafe for StateRegistry
impl Send for StateRegistry
impl Sync for StateRegistry
impl Unpin for StateRegistry
impl !UnwindSafe for StateRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
Create a new handle for an Arc value Read more
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
Clone a handle Read more
§unsafe fn consume_handle(handle: Handle) -> Arc<T>
unsafe fn consume_handle(handle: Handle) -> Arc<T>
Consume a handle, getting back the initial
Arc<> Read more