๐ฆ Rust Generic Structs
= a struct, with a generic type
- Call a specific associated function:
::<T>
(often redundant due to type inference)
Constant parameters
You can pass a constant parameter to a generic struct like so:
struct Person<const AGE: i8> {
age = AGE
}
impl <const AGE: i8> {
fn new (AGE: i8) -> Person<AGE> {
Person { age: AGE}
}
}
Example
struct Person<T> {
name: T
}
Impl can be type specific:
impl Person<String> {
...
}