4 ms·
The direct analog of Rust's trait objects is Swift's protocol objects; call them existential types. Both Rust and Swift have limitations on which traits (protoc
by ridiculous_fish 9y ago
The direct analog of Rust's trait objects is Swift's protocol objects; call them existential types. Both Rust and Swift have limitations on which traits (protocols) can be used as an existential.
Swift forbids existentials when the protocol has an associated type. Rust has a notion of "object safety" which is both more flexible and more complicated, but applies the same restriction in most cases.
I think the closest analog of Swift's `AnySequence<Int>` would be a `Box<Iterator<Item=Int>>`.