I want a vector for elements that contain a trait such as Eq
and I need heterogeneous vectors. For example:
let mut x: Vec<Eq> = Vec::new();
x.push(1);
x.push("hello")
I get an error message that says that Eq
cannot be made into an object:
error[E0038]: the trait `std::cmp::Eq` cannot be made into an object
--> src/main.rs:2:20
|
2 | let mut x: Vec<Eq> = Vec::new();
| ^^ the trait `std::cmp::Eq` cannot be made into an object
|
= note: the trait cannot use `Self` as a type parameter in the supertrait listing
Is it possible to have a list of pointers to things I can compare regardless of their types?
See Question&Answers more detail:os