Skip to content

Instantly share code, notes, and snippets.

@jld
Created September 1, 2012 22:49
Show Gist options
  • Save jld/3590199 to your computer and use it in GitHub Desktop.
Save jld/3590199 to your computer and use it in GitHub Desktop.
Traits on vectors do strange things.
import to_bytes::{IterBytes,iter_le_bytes_2,iter_be_bytes_2};
enum thing = uint;
impl thing : IterBytes {
fn iter_le_bytes(f: to_bytes::Cb) { (*self).iter_le_bytes(f) }
fn iter_be_bytes(f: to_bytes::Cb) { (*self).iter_be_bytes(f) }
}
enum stuff1 = ~[thing];
impl stuff1 : IterBytes {
fn iter_le_bytes(f: to_bytes::Cb) { (*self).iter_le_bytes(f) }
fn iter_be_bytes(f: to_bytes::Cb) { (*self).iter_be_bytes(f) }
}
enum stuff = (uint, ~[thing]);
impl stuff : IterBytes {
fn iter_le_bytes(f: to_bytes::Cb) {
match *self { (ref i, ref v) => iter_le_bytes_2(i, v, f) }
}
fn iter_be_bytes(f: to_bytes::Cb) {
match *self { (ref i, ref v) => iter_be_bytes_2(i, v, f) }
}
}
// minim2.rs:18:40: 18:55 error: failed to find an implementation of trait @core::to_bytes::IterBytes for ~[thing]
// minim2.rs:18 match *self { (ref i, ref v) => iter_le_bytes_2(i, v, f) }
// ^~~~~~~~~~~~~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment