pub struct StateRegistry {
database: SystemDatabase,
client_managed: RwLock<HashMap<TypeId, Box<dyn Any + Send + Sync>>>,
}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§
§database: SystemDatabase§client_managed: RwLock<HashMap<TypeId, Box<dyn Any + Send + Sync>>>Implementations§
Source§impl StateRegistry
impl StateRegistry
Sourcepub fn new_with_memory_db() -> Self
pub fn new_with_memory_db() -> Self
Creates a new StateRegistry backed by an in-memory database.
Sourcepub async fn new_with_db(
configuration: DatabaseConfiguration,
migrations: RepositoryMigrations,
) -> Result<Self, DatabaseError>
pub async fn new_with_db( configuration: DatabaseConfiguration, migrations: RepositoryMigrations, ) -> Result<Self, DatabaseError>
Creates a new StateRegistry backed by a database.
Sourcepub fn setting<T>(&self, key: Key<T>) -> Result<Setting<T>, StateRegistryError>
pub fn setting<T>(&self, key: Key<T>) -> Result<Setting<T>, StateRegistryError>
Get a handle to a setting by its type-safe key.
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>>.
§Errors
This method never fails, but returns a Result for backwards compatibility.
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 UnsafeUnpin 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
§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
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T>
unsafe fn consume_handle(handle: Handle) -> Arc<T>
Arc<> Read more