pub fn create_struct(
    state: &AbstractState,
    struct_index: StructDefinitionIndex,
) -> Result<AbstractState, VMError> {
    let state_copy = state.clone();
    let mut state = state.clone();
    let struct_def = state_copy.module.struct_def_at(struct_index);
    let struct_def_view = StructDefinitionView::new(&state_copy.module, struct_def);
    let tokens: Vec<SignatureToken> = struct_def_view
        .fields()
        .into_iter()
        .flatten()
        .map(|field| field.type_signature().token().as_inner().clone())
        .collect();
    // The logic for determine the struct kind was sourced from `SignatureTokenView`
    // TODO: This will need to be updated when struct type actuals are handled
    let struct_kind = match struct_def_view.is_nominal_resource() {
        true => Kind::Resource,
        false => tokens
            .iter()
            .map(|token| SignatureTokenView::new(&state.module, token).kind(&[]))
            .fold(Kind::Unrestricted, |acc_kind, next_kind| {
                match (acc_kind, next_kind) {
                    (Kind::All, _) | (_, Kind::All) => Kind::All,
                    (Kind::Resource, _) | (_, Kind::Resource) => Kind::Resource,
                    (Kind::Unrestricted, Kind::Unrestricted) => Kind::Unrestricted,
                }
            }),
    };
    let struct_value = AbstractValue::new_struct(
        SignatureToken::Struct(struct_def.struct_handle, tokens),
        struct_kind,
    );
    state.register_set(struct_value);
    Ok(state)
}
/// Construct a struct from abstract values on the stack
/// The struct is stored in the register after creation
Construct a struct from abstract values on the stack
The struct is stored in the register after creation
Construct a struct from abstract values on the stack The struct is stored in the register after creation
pub fn create_struct(
    state: &AbstractState,
    struct_index: StructDefinitionIndex,
) -> Result<AbstractState, VMError> {
    let state_copy = state.clone();
    let mut state = state.clone();
    let struct_def = state_copy.module.struct_def_at(struct_index);
    let struct_def_view = StructDefinitionView::new(&state_copy.module, struct_def);
    let tokens: Vec<SignatureToken> = struct_def_view
        .fields()
        .into_iter()
        .flatten()
        .map(|field| field.type_signature().token().as_inner().clone())
        .collect();
    // The logic for determine the struct kind was sourced from `SignatureTokenView`
    // TODO: This will need to be updated when struct type actuals are handled
    let struct_kind = match struct_def_view.is_nominal_resource() {
        true => Kind::Resource,
        false => tokens
            .iter()
            .map(|token| SignatureTokenView::new(&state.module, token).kind(&[]))
            .fold(Kind::Unrestricted, |acc_kind, next_kind| {
                match (acc_kind, next_kind) {
                    (Kind::All, _) | (_, Kind::All) => Kind::All,
                    (Kind::Resource, _) | (_, Kind::Resource) => Kind::Resource,
                    (Kind::Unrestricted, Kind::Unrestricted) => Kind::Unrestricted,
                }
            }),
    };
    let struct_value = AbstractValue::new_struct(
        SignatureToken::Struct(struct_def.struct_handle, tokens),
        struct_kind,
    );
    state.register_set(struct_value);
    Ok(state)
}
pub fn create_struct ( state : & AbstractState , struct_index : StructDefinitionIndex , ) -> Result < AbstractState , VMError > { let state_copy = state . clone ( ) ; let mut state = state . clone ( ) ; let struct_def = state_copy . module . struct_def_at ( struct_index ) ; let struct_def_view = StructDefinitionView :: new ( & state_copy . module , struct_def ) ; let tokens : Vec < SignatureToken > = struct_def_view . fields ( ) . into_iter ( ) . flatten ( ) . map ( | field | field . type_signature ( ) . token ( ) . as_inner ( ) . clone ( ) ) . collect ( ) ; // The logic for determine the struct kind was sourced from `SignatureTokenView` // TODO: This will need to be updated when struct type actuals are handled let struct_kind = match struct_def_view . is_nominal_resource ( ) { true => Kind :: Resource , false => tokens . iter ( ) . map ( | token | SignatureTokenView :: new ( & state . module , token ) . kind ( & [ ] ) ) . fold ( Kind :: Unrestricted , | acc_kind , next_kind | { match ( acc_kind , next_kind ) { ( Kind :: All , _ ) | ( _ , Kind :: All ) => Kind :: All , ( Kind :: Resource , _ ) | ( _ , Kind :: Resource ) => Kind :: Resource , ( Kind :: Unrestricted , Kind :: Unrestricted ) => Kind :: Unrestricted , } } ) , } ; let struct_value = AbstractValue :: new_struct ( SignatureToken :: Struct ( struct_def . struct_handle , tokens ) , struct_kind , ) ; state . register_set ( struct_value ) ; Ok ( state ) }
Construct a struct from abstract values on the stack
The struct is stored in the register after creation
Construct a struct from abstract values on the stack The struct is stored in the register after creation
state
&AbstractState
struct_index
StructDefinitionIndex