Type aliases
Syntax
TypeAlias :
type
IDENTIFIER GenericParams? (:
TypeParamBounds )? WhereClause? (=
Type )?;
A type alias defines a new name for an existing type. Type aliases are
declared with the keyword type
. Every value has a single, specific type, but
may implement several different traits, or be compatible with several different
type constraints.
For example, the following defines the type Point
as a synonym for the type
(u8, u8)
, the type of pairs of unsigned 8 bit integers:
A type alias to a tuple-struct or unit-struct cannot be used to qualify that type's constructor:
A type alias without the Type specification may only appear as an associated type in a trait.
A type alias with TypeParamBounds may only specified when used as an associated type in a trait.