4 ms·
Note that you can do Swift's protocol oriented programming / portocol extensions in Rust, too: trait Test { fn value(&self) -> i32; } impl dyn Tes
by terhechte 5y ago
Note that you can do Swift's protocol oriented programming / portocol extensions in Rust, too:
trait Test {
fn value(&self) -> i32;
}
impl dyn Test {
fn multiplied(&self) -> i32 {
self.value() * 2
}
}
- Yoric 5y agoWhat does `impl dyn` mean, exactly? That this only works for trait objects?
- ComputerGuru 5y agoThat it works for any type implementing the trait, via vtables. Otherwise, it’s a method specific to the particular type implementing the trait (a concrete implementation but distinct to the specific impl).