pub fn encode(&mut self, export_func_types: bool) -> Result<()> {
        for func in &self.interface.functions {
            assert!(!func.name.is_empty());

            if !matches!(func.kind, FunctionKind::Freestanding) {
                bail!(
                    "unsupported function `{}`: only free-standing functions are currently supported",
                    func.name
                );
            }

            if !matches!(func.abi, Abi::Canonical) {
                bail!(
                    "unsupported function `{}`: only canonical functions are supported",
                    func.name
                );
            }

            if func.is_async {
                bail!(
                    "unsupported function `{}`: only synchronous functions are currently supported",
                    func.name
                );
            }

            let index = match self.func_type_map.get(&FunctionKey {
                interface: self.interface,
                func,
            }) {
                Some(index) => *index,
                None => {
                    let index = self.encode_func_type(func)?;
                    self.func_type_map.insert(
                        FunctionKey {
                            interface: self.interface,
                            func,
                        },
                        index,
                    );
                    index
                }
            };

            if export_func_types {
                self.export_type(&func.name, index)?;
            }

            // TODO: stick interface documentation in a custom section?
        }
        Ok(())
    }
/// Encodes the interface into the internal sections.
///
/// If `export_func_types` is true, then the declared function types
/// will be exported.
///
/// It is expected that this will be `false` when encoding components
/// that export functions instead of types.
Encodes the interface into the internal sections.
If `export_func_types` is true, then the declared function types
will be exported.

It is expected that this will be `false` when encoding components
that export functions instead of types.
Encodes the interface into the internal sections . If ` export_func_types ` is true then the declared function types will be exported . It is expected that this will be ` false ` when encoding components that export functions instead of types .
pub fn encode(&mut self, export_func_types: bool) -> Result<()> {
        for func in &self.interface.functions {
            assert!(!func.name.is_empty());
            if !matches!(func.kind, FunctionKind::Freestanding) {
                bail!(
                    "unsupported function `{}`: only free-standing functions are currently supported",
                    func.name
                );
            }
            if !matches!(func.abi, Abi::Canonical) {
                bail!(
                    "unsupported function `{}`: only canonical functions are supported",
                    func.name
                );
            }
            if func.is_async {
                bail!(
                    "unsupported function `{}`: only synchronous functions are currently supported",
                    func.name
                );
            }
            let index = match self.func_type_map.get(&FunctionKey {
                interface: self.interface,
                func,
            }) {
                Some(index) => *index,
                None => {
                    let index = self.encode_func_type(func)?;
                    self.func_type_map.insert(
                        FunctionKey {
                            interface: self.interface,
                            func,
                        },
                        index,
                    );
                    index
                }
            };
            if export_func_types {
                self.export_type(&func.name, index)?;
            }
            // TODO: stick interface documentation in a custom section?
        }
        Ok(())
    }
pub fn encode ( & mut self , export_func_types : bool ) -> Result < ( ) > { for func in & self . interface . functions { assert ! ( func name is_empty ( ) ) ; if ! matches ! ( func kind FunctionKind Freestanding ) { bail ! ( " " func name ) ; } if ! matches ! ( func abi Abi Canonical ) { bail ! ( " " func name ) ; } if func . is_async { bail ! ( " " func name ) ; } let index = match self . func_type_map . get ( & FunctionKey { interface : self . interface , func , } ) { Some ( index ) => * index , None => { let index = self . encode_func_type ( func ) ? ; self . func_type_map . insert ( FunctionKey { interface : self . interface , func , } , index , ) ; index } } ; if export_func_types { self . export_type ( & func . name , index ) ? ; } // TODO: stick interface documentation in a custom section? } Ok ( ( ) ) }
Encodes the interface into the internal sections.
Encodes the interface into the internal sections .
&mut self
export_func_types
bool
&mut self
export_func_types
bool