Rust does not support trait aliases; you must use type aliases for types or implement the trait directly on your struct. Use the type keyword to create a synonym for a complex type that implements a trait, then use that alias where needed.
use std::fmt::Display;
struct MyStruct;
impl Display for MyStruct {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Hello")
}
}
type MyDisplayAlias = MyStruct;
fn main() {
let s: MyDisplayAlias = MyStruct;
println!("{}", s);
}
Note: If you need to alias a trait itself (e.g., trait MyTrait = Display + Clone), this is not possible in stable Rust yet; you must list the traits explicitly in bounds or use a macro.