Why this fires¶
A bound in a function signature names a trait that the compiler doesn't recognise.
fn format_all<T: Printable>(items: [T]) {
// ^^^^^^^^^ error[TE822]: unknown trait `Printable`
}Common causes:
- A typo (e.g.
Displyinstead ofDisplay,Orddinstead ofOrd). - Using a trait from another language ecosystem (e.g. Rust's
Clone, Haskell'sFunctor). - Referring to a user-defined trait that hasn't been declared yet.
Fix it¶
1. Correct the spelling¶
Check the std-trait catalogue below and use the exact name.
2. Use the right std trait¶
The built-in trait names are: Eq, Ord, Add, Sub, Mul, Div, Mod, Neg, Display, Hash.
// ❌ Unknown trait
fn show<T: Printable>(x: T) { ... }
// ✅ Correct
fn show<T: Display>(x: T) { ... }3. Declare the trait first¶
If you need a custom trait, declare it before using it as a bound:
trait Serializable {
fn serialize(self) -> str
}
fn save<T: Serializable>(value: T) {
let data = value.serialize()
// ...
}