I am learning Rust as a beginner. I'm curious about how can we use numeric values as generics parameters that will be compiled at compile-time similar to template in C++
This is an equivalent C++ code.
template<class T, int dim>
struct vec {
std::array<T, dim> data;
vec(): data() {}
vec(const vec<T, dim>& obj): data(obj.data) {}
~vec() {}
};
int main() {
vec<float, 3> v3;
}
That code above will be compiled the same as
struct vec {
std::array<float, 3> data;
vec(): data() {}
vec(const vec<float, 3>& obj): data(obj.data) {}
~vec() {}
};
int main() {
vec v3;
}