pub fn disassemble_struct_def(&self, struct_def_idx: StructDefinitionIndex) -> Result<String> {
        let struct_definition = self.get_struct_def(struct_def_idx)?;
        let struct_handle = self
            .source_mapper
            .bytecode
            .struct_handle_at(struct_definition.struct_handle);
        let struct_source_map = self
            .source_mapper
            .source_map
            .get_struct_source_map(struct_def_idx)?;

        let field_info: Option<Vec<(&IdentStr, &TypeSignature)>> =
            match struct_definition.field_information {
                StructFieldInformation::Native => None,
                StructFieldInformation::Declared {
                    field_count,
                    fields,
                } => Some(
                    (fields.0..fields.0 + field_count)
                        .map(|i| {
                            let field_definition = self
                                .source_mapper
                                .bytecode
                                .field_def_at(FieldDefinitionIndex(i));
                            let type_sig = self
                                .source_mapper
                                .bytecode
                                .type_signature_at(field_definition.signature);
                            let field_name = self
                                .source_mapper
                                .bytecode
                                .identifier_at(field_definition.name);
                            (field_name, type_sig)
                        })
                        .collect(),
                ),
            };

        let native = if field_info.is_none() { "native " } else { "" };

        let nominal_name = if struct_handle.is_nominal_resource {
            "resource"
        } else {
            "struct"
        };

        let name = self
            .source_mapper
            .bytecode
            .identifier_at(struct_handle.name)
            .to_string();

        let ty_params = Self::disassemble_type_formals(
            &struct_source_map.type_parameters,
            &struct_handle.type_formals,
        );
        let mut fields = match field_info {
            None => vec![],
            Some(field_info) => field_info
                .iter()
                .map(|(name, ty)| {
                    let ty_str =
                        self.disassemble_sig_tok(ty.0.clone(), &struct_source_map.type_parameters)?;
                    Ok(format!("{}: {}", name.to_string(), ty_str))
                })
                .collect::<Result<Vec<String>>>()?,
        };

        if let Some(first_elem) = fields.first_mut() {
            first_elem.insert_str(0, "{\n\t");
        }

        if let Some(last_elem) = fields.last_mut() {
            last_elem.push_str("\n}");
        }

        Ok(format!(
            "{native}{nominal_name} {name}{ty_params} {fields}",
            native = native,
            nominal_name = nominal_name,
            name = name,
            ty_params = ty_params,
            fields = &fields.join(",\n\t"),
        ))
    }
// The struct defs will filter out the structs that we print to only be the ones that are
// defined in the module in question.
The struct defs will filter out the structs that we print to only be the ones that are
defined in the module in question.
The struct defs will filter out the structs that we print to only be the ones that are defined in the module in question .
pub fn disassemble_struct_def(&self, struct_def_idx: StructDefinitionIndex) -> Result<String> {
        let struct_definition = self.get_struct_def(struct_def_idx)?;
        let struct_handle = self
            .source_mapper
            .bytecode
            .struct_handle_at(struct_definition.struct_handle);
        let struct_source_map = self
            .source_mapper
            .source_map
            .get_struct_source_map(struct_def_idx)?;
        let field_info: Option<Vec<(&IdentStr, &TypeSignature)>> =
            match struct_definition.field_information {
                StructFieldInformation::Native => None,
                StructFieldInformation::Declared {
                    field_count,
                    fields,
                } => Some(
                    (fields.0..fields.0 + field_count)
                        .map(|i| {
                            let field_definition = self
                                .source_mapper
                                .bytecode
                                .field_def_at(FieldDefinitionIndex(i));
                            let type_sig = self
                                .source_mapper
                                .bytecode
                                .type_signature_at(field_definition.signature);
                            let field_name = self
                                .source_mapper
                                .bytecode
                                .identifier_at(field_definition.name);
                            (field_name, type_sig)
                        })
                        .collect(),
                ),
            };
        let native = if field_info.is_none() { "native " } else { "" };
        let nominal_name = if struct_handle.is_nominal_resource {
            "resource"
        } else {
            "struct"
        };
        let name = self
            .source_mapper
            .bytecode
            .identifier_at(struct_handle.name)
            .to_string();
        let ty_params = Self::disassemble_type_formals(
            &struct_source_map.type_parameters,
            &struct_handle.type_formals,
        );
        let mut fields = match field_info {
            None => vec![],
            Some(field_info) => field_info
                .iter()
                .map(|(name, ty)| {
                    let ty_str =
                        self.disassemble_sig_tok(ty.0.clone(), &struct_source_map.type_parameters)?;
                    Ok(format!("{}: {}", name.to_string(), ty_str))
                })
                .collect::<Result<Vec<String>>>()?,
        };
        if let Some(first_elem) = fields.first_mut() {
            first_elem.insert_str(0, "{\n\t");
        }
        if let Some(last_elem) = fields.last_mut() {
            last_elem.push_str("\n}");
        }
        Ok(format!(
            "{native}{nominal_name} {name}{ty_params} {fields}",
            native = native,
            nominal_name = nominal_name,
            name = name,
            ty_params = ty_params,
            fields = &fields.join(",\n\t"),
        ))
    }
pub fn disassemble_struct_def ( & self , struct_def_idx : StructDefinitionIndex ) -> Result < String > { let struct_definition = self . get_struct_def ( struct_def_idx ) ? ; let struct_handle = self . source_mapper . bytecode . struct_handle_at ( struct_definition . struct_handle ) ; let struct_source_map = self . source_mapper . source_map . get_struct_source_map ( struct_def_idx ) ? ; let field_info : Option < Vec < ( & IdentStr , & TypeSignature ) > > = match struct_definition . field_information { StructFieldInformation :: Native => None , StructFieldInformation :: Declared { field_count , fields , } => Some ( ( fields . 0 .. fields . 0 + field_count ) . map ( | i | { let field_definition = self . source_mapper . bytecode . field_def_at ( FieldDefinitionIndex ( i ) ) ; let type_sig = self . source_mapper . bytecode . type_signature_at ( field_definition . signature ) ; let field_name = self . source_mapper . bytecode . identifier_at ( field_definition . name ) ; ( field_name , type_sig ) } ) . collect ( ) , ) , } ; let native = if field_info . is_none ( ) { " " } else { " " } ; let nominal_name = if struct_handle . is_nominal_resource { " " } else { " " } ; let name = self . source_mapper . bytecode . identifier_at ( struct_handle . name ) . to_string ( ) ; let ty_params = Self :: disassemble_type_formals ( & struct_source_map . type_parameters , & struct_handle . type_formals , ) ; let mut fields = match field_info { None => vec ! [ ] , Some ( field_info ) => field_info . iter ( ) . map ( | ( name , ty ) | { let ty_str = self . disassemble_sig_tok ( ty . 0 . clone ( ) , & struct_source_map . type_parameters ) ? ; Ok ( format ! ( " " name to_string ( ) ty_str ) ) } ) . collect :: < Result < Vec < String > > > ( ) ? , } ; if let Some ( first_elem ) = fields . first_mut ( ) { first_elem . insert_str ( 0 , " \n \t " ) ; } if let Some ( last_elem ) = fields . last_mut ( ) { last_elem . push_str ( " \n " ) ; } Ok ( format ! ( " " native native nominal_name nominal_name name name ty_params ty_params fields fields join ( " \n \t " ) ) ) }
The struct defs will filter out the structs that we print to only be the ones that are
defined in the module in question.
The struct defs will filter out the structs that we print to only be the ones that are defined in the module in question .
&self
struct_def_idx
StructDefinitionIndex
&self
struct_def_idx
StructDefinitionIndex