Skip to main content
Generic structs and type aliases exist only at the type level and incur no runtime cost.
Example usage:

Type arguments must be specified

When referencing a generic Container, T must be provided explicitly:
For generic functions, type arguments can be inferred from the call site:

Default type arguments

A type parameter can have a default type: <T = xxx>. Such type parameters may be omitted at use sites.
Type arguments cannot currently reference one another; expressions such as T2 = T1 are invalid.

Not only structs, but also type aliases

The following example demonstrates a generic type alias Response<TResult, TError>:

Methods for generic types

Methods for generics are declared exactly as for regular structures. In this form, the compiler treats T (unknown symbol) as a type parameter:
Notice the first self parameter. Without it, a method will be static. See Functions and methods for examples.