E4077#
不知道如何导出类型的特征。
MoonBit 允许你为你的类型派生一些预定义特征的实现。这意味着你无法让 MoonBit 自动派生你自定义的特征。
错误示例#
///|
trait T {
f(Self) -> Int
}
///|
struct A(Int) derive(T) // Error: Don't know how to derive trait T for type A
建议#
您可以手动实现该特性:
///|
priv trait T {
f(Self) -> Int
}
///|
priv struct A(Int)
///|
impl T for A with f(self : A) -> Int {
self.0
}
///|
test {
let value : A = A(1)
inspect(value.f(), content="1")
}