How to fill an array of type [impl T;2]?

I'm declaring a function which has a parameter of type [impl Tr;2] , but I don't known how to construct an argument of this type. ln the following code , line A does not work. Please give me some tips. thanks in advance.

fn main() {
  trait Tr {
    fn test(&self) {}
  struct U;
  struct V;
  impl Tr for U {}
  impl Tr for V {}
  //let x = [U,V];   // A
  fn test(x:[impl Tr;2]) {
    for x in x {

impl Tr means "one specific type", not "any type", it can't refer to both U and V in the same statement. You probably want [Box<dyn Tr>; 2] instead.

1 Like

thank you. this really clarify me the semantic of impl T.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.