關於 trait,moonbit 的 + 和 Rust 的 + 是不是完全不同?如下述rs代碼:
trait A {}
trait B {}
struct S {}
// impl A for S {}
// impl B for S {}
trait C : A + B + Sized { fn bar(self) {} }
impl C for S {}
fn main() {
let s = S {};
s.bar();
}
會報錯:
the trait bound `S: A` is not satisfied
the trait bound `S: B` is not satisfied
但是 mbt 就不同了:
trait A { foo(Self) -> Unit }
trait B { foo(Self) -> Unit }
struct S {}
// impl A for S with foo(_) { println("A::foo") } // 显式实现 A
// impl B for S with foo(_) { println("B::foo") } // 显式实现 B
trait C : A + B { bar(Self) -> Unit }
impl C for S with bar(_) { println("C::bar") } // 需要 A 和 B 已实现
fn main {
let s = S::{}
s.bar()
}
這段代碼居然編譯通過了!
所以 mbt 的 + 是什麽意思呢?這似乎和 rs 完全不一樣。