-
struct Offer<T: key + store> has key, store { 请问这里的
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
https://move-book.com/cn/advanced-topics/understanding-generics.html 我们已经学习了 abilities,它们可以作为泛型的限制符来使用,限制符的名称和 ability 相同。 fun name<T: copy>() {} // allow only values that can be copied struct name<T: copy + drop> { value: T } // T can be copied and dropped |
Beta Was this translation helpful? Give feedback.
-
function 感觉不可能操作 struct 的 abilities,感觉只能是限制: 传入的泛型必须有 key + store 能力 |
Beta Was this translation helpful? Give feedback.
https://move-book.com/cn/advanced-topics/understanding-generics.html
abilities 限制符
我们已经学习了 abilities,它们可以作为泛型的限制符来使用,限制符的名称和 ability 相同。
fun name<T: copy>() {} // allow only values that can be copied
fun name<T: copy + drop>() {} // values can be copied and dropped
fun name<T: key + store + drop + copy>() {} // all 4 abilities are present
也可以在结构体泛型参数中使用:
struct name<T: copy + drop> { value: T } // T can be copied and dropped
struct name<T: stored> { value: T } // T can be stored in global storage
请记住 + 这个语法符号,第一眼看上去可能不太适应,因为很少有语言在关键字列表中使用 +。