E0116

Rust Programming Language

Severity: Minor

What it means

rustc: error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined.
Rust's error index: an inherent implementation, impl Type { ... } with no trait, is only allowed in the crate where the type was defined. impl Vec { } fails because Vec comes from the standard library.
A type alias doesn't get around it: type Bytes = Vec; followed by impl Bytes { } gives the same error.

Affected Models

  • rustc and cargo, all Rust editions

How to Fix It

  1. Define a trait with the methods you want, and implement it for the type: trait ByteSum { fn total(&self) -> u32; } and impl ByteSum for Vec<u8> { ... }.

    Bring the trait into scope with use wherever you call its methods.

  2. Or wrap the type in a struct of your own, a newtype, and write the impl for that: struct Bytes(Vec<u8>); impl Bytes { ... }.