Generics
Type parameters, monomorphization, and call-site inference.
fn id<T>(x: T) {
return x
}
fn main() {
print(id<i32>(42))
print(id<i32>(42))
}fn id<T>(x: T) -> i32 {
return x
}
fn main() -> void {
print(id<i32>(42))
print(id<i32>(42))
}Monomorphization generates specialized functions at compile time (id__i32, etc.). Generic calls use ident < Type > ( syntax when types are explicit.
See also Comptime evaluation for optional compile-time folding, Ownership UX for return-type inference, and CONF-GEN-* in the conformance suite.