fn make_state_import(
    cx: &mut ModuleContext<'_>,
    module: Module,
) -> Vec<impl wasm_encoder::Section> {
    let mut sections = vec![];

    // Define the state instance's type.
    let state_instance_ty = module.define_state_instance_type(cx);

    // Alias the state instance type from the umbrella.
    let mut alias = wasm_encoder::AliasSection::new();
    alias.outer_type(0, state_instance_ty.index());
    sections.push(StateImportSection::Alias(alias));

    let state_instance_type_index = u32::try_from(module.types(cx).len()).unwrap();
    module.push_aliased_type(cx, state_instance_ty);

    // Define the import of the state instance, using the type
    // we just defined.
    let mut imports = wasm_encoder::ImportSection::new();
    imports.import(
        "__wizer_state",
        None,
        wasm_encoder::EntityType::Instance(state_instance_type_index),
    );
    sections.push(StateImportSection::Import(imports));

    return sections;

    enum StateImportSection {
        Alias(wasm_encoder::AliasSection),
        Import(wasm_encoder::ImportSection),
    }

    impl wasm_encoder::Section for StateImportSection {
        fn id(&self) -> u8 {
            match self {
                StateImportSection::Alias(s) => s.id(),
                StateImportSection::Import(s) => s.id(),
            }
        }

        fn encode<S>(&self, sink: &mut S)
        where
            S: Extend<u8>,
        {
            match self {
                StateImportSection::Alias(s) => s.encode(sink),
                StateImportSection::Import(s) => s.encode(sink),
            }
        }
    }
}
/// Make an import section that imports a code module's state instance import.
Make an import section that imports a code module's state instance import.
Make an import section that imports a code module ' s state instance import .
fn make_state_import(
    cx: &mut ModuleContext<'_>,
    module: Module,
) -> Vec<impl wasm_encoder::Section> {
    let mut sections = vec![];
    // Define the state instance's type.
    let state_instance_ty = module.define_state_instance_type(cx);
    // Alias the state instance type from the umbrella.
    let mut alias = wasm_encoder::AliasSection::new();
    alias.outer_type(0, state_instance_ty.index());
    sections.push(StateImportSection::Alias(alias));
    let state_instance_type_index = u32::try_from(module.types(cx).len()).unwrap();
    module.push_aliased_type(cx, state_instance_ty);
    // Define the import of the state instance, using the type
    // we just defined.
    let mut imports = wasm_encoder::ImportSection::new();
    imports.import(
        "__wizer_state",
        None,
        wasm_encoder::EntityType::Instance(state_instance_type_index),
    );
    sections.push(StateImportSection::Import(imports));
    return sections;
    enum StateImportSection {
        Alias(wasm_encoder::AliasSection),
        Import(wasm_encoder::ImportSection),
    }
    impl wasm_encoder::Section for StateImportSection {
        fn id(&self) -> u8 {
            match self {
                StateImportSection::Alias(s) => s.id(),
                StateImportSection::Import(s) => s.id(),
            }
        }
        fn encode<S>(&self, sink: &mut S)
        where
            S: Extend<u8>,
        {
            match self {
                StateImportSection::Alias(s) => s.encode(sink),
                StateImportSection::Import(s) => s.encode(sink),
            }
        }
    }
}
fn make_state_import ( cx : & mut ModuleContext < ' _ > , module : Module , ) -> Vec < impl wasm_encoder :: Section > { let mut sections = vec ! [ ] ; // Define the state instance's type. let state_instance_ty = module . define_state_instance_type ( cx ) ; // Alias the state instance type from the umbrella. let mut alias = wasm_encoder :: AliasSection :: new ( ) ; alias . outer_type ( 0 , state_instance_ty . index ( ) ) ; sections . push ( StateImportSection :: Alias ( alias ) ) ; let state_instance_type_index = u32 :: try_from ( module . types ( cx ) . len ( ) ) . unwrap ( ) ; module . push_aliased_type ( cx , state_instance_ty ) ; // Define the import of the state instance, using the type // we just defined. let mut imports = wasm_encoder :: ImportSection :: new ( ) ; imports . import ( " " , None , wasm_encoder :: EntityType :: Instance ( state_instance_type_index ) , ) ; sections . push ( StateImportSection :: Import ( imports ) ) ; return sections ; enum StateImportSection { Alias ( wasm_encoder :: AliasSection ) , Import ( wasm_encoder :: ImportSection ) , } impl wasm_encoder :: Section for StateImportSection { fn id ( & self ) -> u8 { match self { StateImportSection :: Alias ( s ) => s . id ( ) , StateImportSection :: Import ( s ) => s . id ( ) , } } fn encode < S > ( & self , sink : & mut S ) where S : Extend < u8 > , { match self { StateImportSection :: Alias ( s ) => s . encode ( sink ) , StateImportSection :: Import ( s ) => s . encode ( sink ) , } } } }
Make an import section that imports a code module's state instance import.
Make an import section that imports a code module ' s state instance import .
cx
&mut ModuleContext<'_>
module
Module
cx
&mut ModuleContext<'_>
module
Module