Skip to content

Comment on Patterns with Rust Typesparent

Comments

Rust has that, it's called a type alias: 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.

Type 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.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.