Contents

  1. What Is the Orphan Rule Actually Protecting Against?
  2. Why the Two Usual Workarounds Fall Short
    1. 1. Building it into the library
    2. 2. Wrap it in a NewType yourself
  3. Adding a Generic Slot to the Trait
  4. The Position of the Local Type Matters
  5. A Truly Standalone models Crate
  6. Real-World Example: How This Works in Kova

Write Rust for long enough, and you are bound to run into error[E0117].

Take a simple, everyday scenario. You pull in a serialization library that defines a ToJson trait, along with a third-party type library like uuid. You want to turn a uuid::Uuid into JSON, so you naturally write:

impl ToJson for uuid::Uuid {
    fn to_json(&self) -> String {
        format!("\"{}\"", self)
    }
}