Move语言社区

【Move进阶】Function泛型参数

address 0x2{
module Box2{

    struct Box<T1:copy + drop, T2:copy + drop + store> has copy,drop {
	contents_1: T1,
	contents_2: T2,
    }


    fun create_box<T1:copy + drop, T2:copy + drop + store>(val_1:T1, val_2:T2):Box<T1, T2> {
	Box {contents_1:val_1, contents_2:val_2}
    }

    public(script) fun create_bool_box<T2:copy + drop + store>(val_2:T2) {
        let _ = Self::create_box<bool, T2>(false, val_2);
    }

    public(script) fun create_bool_u64_box() {
	let _ = Self::create_box<bool, u64>(false, 100);
    }
}
}