▲ | Kranar 4 days ago | |||||||
While this has nothing to do with the expression problem, it's worth noting that in any case your solution does not work in general. Rust does let you impl traits for types or traits that are inside of your crate, so your example strictly speaking works, but it does not let you impl traits if both the type and the trait are not inside of your crate. This is known as the orphan rule: https://doc.rust-lang.org/reference/items/implementations.ht... As the article points out, the expression problem itself is pretty simple to solve for code that you control, it's when writing modular software that can vary independently that gives rise to issues. | ||||||||
▲ | ceronman 4 days ago | parent [-] | |||||||
Why would the the orphan rule be a problem here? The orphan rule only disallow impls if both the trait and the type are defined outside the crate. But in this example if you are adding a new type (struct) or a new operation (trait), well this new item should be in your crate, so all the impls that follow are allowed. | ||||||||
|