Rust supports writing generic code that is later bound with more concrete types, either during compile time or during runtime. People who are familiar with templates in C++ might notice that generics in Rust are pretty similar to templates, as far as syntax goes. The following example illustrates how to use generic programming. We also introduce some new constructs which we haven't discussed before, which we will explain as we proceed.
Much like C and C++, a Rust struct defines a user-defined type that aggregates multiple logically connected resources in one unit. Our struct here defines a tuple of two variables. We define a generic struct and we use a generic type parameter, written here as <T>. Each member of the struct is defined to be of that type. We later define a generic function that sums the two elements of the tuple. Let&apos...