Skip to main content

create_nested_instance

Function create_nested_instance 

Source
pub fn create_nested_instance<S: State>(
    definition: Arc<ModuleDefinition<S>>,
    context: Arc<GlobalContext>,
) -> Result<ModuleInstance<S>>
Expand description

Create a nested module instance and register its state in the GlobalContext.

This creates a ModuleInstance from the given definition, registers its initial state in the GlobalContext under the module’s lowercase name, and mounts the instance.

This is the Rust equivalent of the TypeScript SDK’s createNestedModuleInstances().

§Example

use hypen_server::prelude::*;

let ctx = Arc::new(GlobalContext::new());
let def = Arc::new(ModuleBuilder::<MyState>::new("Feed")
    .state(MyState::default())
    .build());

let instance = create_nested_instance(def, ctx.clone()).unwrap();
assert!(ctx.has_module("feed"));