Answers for "rust•armanazi•trait•external•implement•coherence•orphan"

0

rust•armanazi•trait•external•implement•coherence•orphan

But we can’t implement external traits on external types. For example, we can’t implement the Display trait on Vec<T> within our aggregator crate, because Display and Vec<T> are defined in the standard library and aren’t local to our aggregator crate.
This restriction is part of a property of programs called coherence, and more specifically the orphan rule, so named because the parent type is not present. This rule ensures that other people’s code can’t break your code and vice versa. 
Without the rule, two crates could implement the same trait for the same type, and Rust wouldn’t know which implementation to use.
Posted by: Guest on March-18-2022

Code answers related to "rust•armanazi•trait•external•implement•coherence•orphan"

Browse Popular Code Answers by Language