5 ms·
Rust has that, it's called a type alias: https://doc.rust-lang.org/reference/items/type-aliases.html https://doc.rust-lang.org/reference/items/type-aliases.html
by jcrites 3y ago
Rust has that, it's called a type alias: https://doc.rust-lang.org/reference/items/type-aliases.html https://doc.rust-lang.org/reference/items/type-aliases.html
I'm not familiar with that Go feature, but in Rust it's just introducing another name for a type. I've usually seen it used to introduce simpler names for complex types.
- duped 3y agoType aliases and new types are two subtly different features. The new type pattern allows you to provide new impls for the underlying type (it is a new type after all) while the type alias is pure sugar where type T = U allows the string T to be substituted for U in any place where T is imported. If U is a foreign type you cannot provide new trait impls for it.