title: How to compare contents an owned vector to a static vector in Rust?
body: <p>As a part of a test, I want to assert that a function returns a vector with proper contents. I therefore made the expected data available as a static variable. However, I can't find a proper way to compare the contents of a managed vector to the static vector variable.</p>
  
  <pre><code>#[test]
  fn test_my_data_matches_expected_data () {
    static expected_data: [u8, ..3] = [1, 2, 3];
    let my_data: ~[u8] = ~[1, 2, 3];  // actually returned by the function to test
  
    // This would be obvious, but fails:
    // -&gt; mismatched types: expected `~[u8]` but found `[u8 * 3]`
    assert_eq!(my_data, expected_data);
  
    // Static vectors are told to be available as a borrowed pointer,
    // so I tried to borrow a pointer from my_data and compare it:
    // -&gt; mismatched types: expected `&amp;const ~[u8]` but found `[u8 * 3]`
    assert_eq!(&amp;my_data, expected_data);
  
    // Dereferencing also doesn't work:
    // -&gt; type ~[u8] cannot be dereferenced
    assert_eq!(*my_data, expected_data);
  
    // Copying the static vector to a managed one works, but this
    // involves creating a copy of the data and actually defeats
    // the reason to declare it statically:
    assert_eq!(my_data, expected_data.to_owned());
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Update:</strong> Assigning a reference to the static vector before comparing it works around the problem, so I ended up with a small macro to assert equality of vectors:</p>
  
  <pre><code>macro_rules! assert_typed_eq (($T: ty, $given: expr, $expected: expr) =&gt; ({
    let given_val: &amp;$T = $given;
    let expected_val: &amp;$T = $expected;
    assert_eq!(given_val, expected_val);
  }))
  </code></pre>
  
  <p>Usage: <code>assert_typed_eq([u8], my_data, expected_data);</code></p>