pub struct StateRegistry {
database: SystemDatabase,
client_managed: AnyMap,
pub(crate) debug: DebugRegistry,
}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: AnyMap§debug: DebugRegistryDev-only index of per-type get/set/list shims backing the generic debug
browse. Populated at registration (both client- and SDK-managed), where
the concrete type is known. See crate::debug.
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: Persist>(
&self,
key: Key<T>,
) -> Result<Setting<T>, StateRegistryError>
pub fn setting<T: Persist>( &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.
Sourcepub async fn wipe(&self) -> Result<(), DatabaseError>
pub async fn wipe(&self) -> Result<(), DatabaseError>
Wipes all state from this registry, and deletes any files or databases associated with it. Intended to be used during logout, where the Client will be dropped right after.
§Warning
This closes the SDK-managed database and deletes persistent storage (SQLite file + WAL/SHM,
IndexedDB database). Outstanding Repository handles will return
DatabaseError::Closed on subsequent operations. Client-managed repositories are also
cleared.
Source§impl StateRegistry
Generic browse over registered repositories, addressed by type name. Backs
StateDebug; bypasses the type-safe public API.
impl StateRegistry
Generic browse over registered repositories, addressed by type name. Backs
StateDebug; bypasses the type-safe public API.
Sourcepub fn debug_register_migrations(&self, migrations: &RepositoryMigrations)
pub fn debug_register_migrations(&self, migrations: &RepositoryMigrations)
Register debug shims for the SDK-managed types declared in migrations.
new_with_db already does this, but the memory-backed
registry the wasm and mobile bindings build does not go through it, so
without this call the browse would only see client-managed types. Idempotent
(shims are keyed by type).
Sourcepub(crate) fn debug_types(&self) -> Vec<String>
pub(crate) fn debug_types(&self) -> Vec<String>
Names of every registered repository (client- and SDK-managed).
Sourcepub(crate) async fn debug_list(&self, type_name: &str) -> Vec<Value>
pub(crate) async fn debug_list(&self, type_name: &str) -> Vec<Value>
List a repository’s values as JSON, addressed by type name. Values only; the repository API lists values without their keys.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for StateRegistry
impl !RefUnwindSafe for StateRegistry
impl !UnwindSafe for StateRegistry
impl Send for StateRegistry
impl Sync for StateRegistry
impl Unpin for StateRegistry
impl UnsafeUnpin 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