Skip to main content

ClientModuleInit

Trait ClientModuleInit 

Source
pub trait ClientModuleInit: ModuleInit + Sized {
    type Module: ClientModule;

    // Required methods
    fn supported_api_versions(&self) -> MultiApiVersion;
    fn init<'life0, 'life1, 'async_trait>(
        &'life0 self,
        args: &'life1 ClientModuleInitArgs<Self>,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Module>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn kind() -> ModuleKind { ... }
    fn recovery_mode(&self) -> RecoveryMode { ... }
    fn prepare_recovery<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _args: &'life1 ClientModuleRecoveryPrepareArgs,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn recover<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _args: &'life1 ClientModuleRecoverArgs<Self>,
        _snapshot: Option<&'life2 <Self::Module as ClientModule>::Backup>,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Amount>>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn get_database_migrations(
        &self,
    ) -> BTreeMap<DatabaseVersion, ClientModuleMigrationFn> { ... }
    fn used_db_prefixes(&self) -> Option<BTreeSet<u8>> { ... }
}

Required Associated Types§

Required Methods§

Source

fn supported_api_versions(&self) -> MultiApiVersion

Api versions of the corresponding server side module’s API that this client module implementation can use.

Source

fn init<'life0, 'life1, 'async_trait>( &'life0 self, args: &'life1 ClientModuleInitArgs<Self>, ) -> Pin<Box<dyn Future<Output = Result<Self::Module>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Initialize a ClientModule instance from its config

Provided Methods§

Source

fn kind() -> ModuleKind

Source

fn recovery_mode(&self) -> RecoveryMode

How this module’s recovery relates to using the module, see RecoveryMode.

Must be overridden together with Self::recover: leaving this at RecoveryMode::None while implementing a recovery leaves that recovery unreachable, and overriding only this makes the module’s recovery fail.

Source

fn prepare_recovery<'life0, 'life1, 'async_trait>( &'life0 self, _args: &'life1 ClientModuleRecoveryPrepareArgs, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Commit the boundary between a recovery and live operation.

Called on every client open that starts or resumes a recovery, before Self::init and before the module joins the module registry.

RecoveryMode::Usable is a claim that the recovery and the live module cannot interfere: the recovery must not rewrite state the module also writes, and must not rediscover what the live module is about to do. Whatever separates the two has to be recorded durably here, because everything after this point can run concurrently with the module. If this fails the client fails to open and neither the module nor its recovery is started, so Self::recover may rely on the boundary having been committed.

Only called for modules whose Self::recovery_mode is RecoveryMode::Usable.

Source

fn recover<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _args: &'life1 ClientModuleRecoverArgs<Self>, _snapshot: Option<&'life2 <Self::Module as ClientModule>::Backup>, ) -> Pin<Box<dyn Future<Output = Result<Option<Amount>>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Recover the state of the client module, optionally from an existing snapshot.

Only called for modules whose Self::recovery_mode is not RecoveryMode::None.

On success, returns the total amount recovered from this module, if the module tracks it (None for modules that can’t determine the amount at recovery-completion time). This is surfaced in the ModuleRecoveryCompleted event.

If Err is returned, the higher level client/application might try again at a different time (client restarted, code version changed, etc.)

Source

fn get_database_migrations( &self, ) -> BTreeMap<DatabaseVersion, ClientModuleMigrationFn>

Retrieves the database migrations from the module to be applied to the database before the module is initialized. The database migrations map is indexed on the “from” version.

Source

fn used_db_prefixes(&self) -> Option<BTreeSet<u8>>

Db prefixes used by the module

If Some is returned, it should contain list of database prefixes actually used by the module for it’s keys.

In (some subset of) non-production tests, module database will be scanned for presence of keys that do not belong to this list to verify integrity of data and possibly catch any unforeseen bugs.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§