// ./src/generics/gen_fn.md struct A; // Concrete type `A`. struct S(A); // Concrete type `S`. struct SGen(T); // Generic type `SGen`. // The following functions all take ownership of the variable passed into // them and immediately go out of scope, freeing the variable. // Define a function `reg_fn` that takes an argument `_s` of type `S`. // This has no `` so this is not a generic function. fn reg_fn(_s: S) {} // Define a function `gen_spec_t` that takes an argument `_s` of type `SGen`. // It has been explicitly given the type parameter `A`, but because `A` has not // been specified as a generic type parameter for `gen_spec_t`, it is not generic. fn gen_spec_t(_s: SGen) {} // Define a function `gen_spec_i32` that takes an argument `_s` of type `SGen`. // It has been explicitly given the type parameter `i32`, which is a specific type. // Because `i32` is not a generic type, this function is also not generic. fn gen_spec_i32(_s: SGen) {} // Define a function `generic` that takes an argument `_s` of type `SGen`. // Because `SGen` is preceded by ``, this function is generic over `T`. fn generic(_s: SGen) {} fn part0() { // Using the non-generic functions reg_fn(S(A)); // Concrete type. gen_spec_t(SGen(A)); // Implicitly specified type parameter `A`. gen_spec_i32(SGen(6)); // Implicitly specified type parameter `i32`. // Explicitly specified type parameter `char` to `generic()`. generic::(SGen('a')); // Implicitly specified type parameter `char` to `generic()`. generic(SGen('c')); } pub fn main() { part0(); }