Type Aliases
Spice supports defining type aliases like this:
Usage¶
| Spice | |
|---|---|
True aliases vs. type constraints¶
The type keyword serves two different purposes depending on what follows it:
type Name alias OtherType — creates a true alias. Name and OtherType are completely interchangeable; the
compiler treats them as the same type:
| Spice | |
|---|---|
type Name A|B|C — declares a generic type constraint, not an alias. It does not create a new type on its own;
it is only meaningful as a template parameter in a generic function, procedure, or struct. It restricts which concrete
types may be substituted for that parameter:
| Spice | |
|---|---|
Using type T dyn as a constraint means the generic type parameter is unconstrained and may be substituted by any
type.