Rust Traits restriction
From Rust Traits page:
There’s one more restriction on implementing traits: either the trait, or the type you’re writing the impl for, must be defined by you. So, we could implement the HasArea type for i32, because HasArea is in our code. But if we tried to implement ToString, a trait provided by Rust, for i32, we could not, because neither the trait nor the type are in our code.
I’m curious to know why Rust has this restriction. And, if it’s a technical limitation, how Swift overcomes it.
Because in Swift you can to it:
extension Int: SequenceType { public func generate() -> AnyGenerator @alexito4 The restriction in Rust ensures that at most one impl can apply to a type -- never any ambiguity. See https://t.co/TG0woMAxey
If you liked this article please consider supporting me