I am trying to make this code more concise and to get rid of redundant variables. Is it possible to do so?
trait Foo {}
impl Foo for i32 {}
impl Foo for String {}
fn main() {
let xi32: i32 = 10;
let y = String::from("ooo");
let mut foo_list: Vec<&Foo> = vec![];
foo_list.push(&xi32 as &Foo);
foo_list.push(&y as &Foo);
}
The following variant doesn't work:
foo_list.push(10 as Foo);
error[E0620]: cast to unsized type: `{integer}` as `Foo`
--> src/main.rs:11:19
|
11 | foo_list.push(10 as Foo);
| ^^^^^^^^^
|
help: consider using a box or reference as appropriate
--> src/main.rs:11:19
|
11 | foo_list.push(10 as Foo);
| ^^