title: Are polymorphic variables allowed?
body: <p>I have various structs that all implement the same trait. I want to branch on some condition, deciding at runtime which of those structs to instantiate. Then, regardless of which branch I followed, I want to call methods from that trait.</p>
  
  <p>Is this possible in Rust? I'm hoping to achieve something like the following (which does not compile):</p>
  
  <pre><code>trait Barks {
      fn bark(&amp;self);
  }
  
  struct Dog;
  
  impl Barks for Dog {
      fn bark(&amp;self) {
          println!("Yip.");
      }
  }
  
  struct Wolf;
  
  impl Barks for Wolf {
      fn bark(&amp;self) {
          println!("WOOF!");
      }
  }
  
  fn main() {
      let animal: Barks;
      if 1 == 2 {
          animal = Dog;
      } else {
          animal = Wolf;
      }
      animal.bark();
  }
  </code></pre>