Skip to main content

StateRegistry

Struct StateRegistry 

Source
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: DebugRegistry

Dev-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

Source

pub fn new_with_memory_db() -> Self

Creates a new StateRegistry backed by an in-memory database.

Source

pub async fn new_with_db( configuration: DatabaseConfiguration, migrations: RepositoryMigrations, ) -> Result<Self, DatabaseError>

Creates a new StateRegistry backed by a database.

Source

pub fn setting<T: Persist>( &self, key: Key<T>, ) -> Result<Setting<T>, StateRegistryError>

Get a handle to a setting by its type-safe key.

Source

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.

Source

fn get_client_managed<T: RepositoryItem>( &self, ) -> Option<Arc<dyn Repository<T>>>

Retrieves a client-managed repository from the map given its type.

Source

fn get_sdk_managed<T: RepositoryItem>( &self, ) -> Result<Arc<dyn Repository<T>>, StateRegistryError>

Retrieves a SDK-managed repository from the database.

Source

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.

Source

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.

Source

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).

Source

pub(crate) fn debug_types(&self) -> Vec<String>

Names of every registered repository (client- and SDK-managed).

Source

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.

Source

pub(crate) async fn debug_get( &self, type_name: &str, key: &str, ) -> Option<Value>

Read one item by type name and string key, as JSON.

Source

pub(crate) async fn debug_set( &self, type_name: &str, key: &str, value: Value, ) -> bool

Write one item by type name and string key. Returns false on an unknown type, a bad key, a value that does not deserialize, or a failed write.

Trait Implementations§

Source§

impl Debug for StateRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T> ⓘ
where T: Sized,

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T> ⓘ

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T> ⓘ

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
§

unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ

Consume a handle, getting back the initial Arc<> Read more
§

unsafe fn get_arc(handle: Handle) -> Arc<Self> ⓘ

Get a clone of the Arc<> using a “borrowed” handle. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more