Move语言社区

【Move进阶】Copy Ability

address 0x2 {
module AbilityExample2 {
    use 0x1::Debug;

    struct CopyStruct has copy {value:u64}
    struct MoveStruct {value:u64}

    public fun new_copy_struct() : CopyStruct {
	CopyStruct {value:100}
    }

    public fun destroy_copy_struct(copy_struct: CopyStruct) {
	let CopyStruct{value:_} = copy_struct;
    }

    public fun new_move_struct() : MoveStruct {
	MoveStruct {value:200}
    }

    public fun destroy_move_struct(move_struct: MoveStruct) {
	let MoveStruct {value:_} = move_struct;
    }

    public fun test() {
	let copy_struct = Self::new_copy_struct();
        let move_struct = Self::new_move_struct();
        Self::destroy_copy_struct(copy copy_struct);
	//Self::destroy_move_struct(copy move_struct);
        Self::destroy_move_struct(move_struct);
	Debug::print(&copy_struct.value);
	//Debug::print(&move_struct.value);
	Self::destroy_copy_struct(copy_struct);
    }
}
}