I'm trying to pack columnar data so that it can be sent to a server.
I wanted to be able to pass any suitable vector to the sending function, so I did this (brief version):
enum Column {
Short(Vec<i16>),
Int(Vec<i32>),
}
impl Column {
fn as_bytes(&mut self) -> &[u8] {
use Column::*; // weird
match self {
Short(vec) => unsafe { (vec.align_to::<u8>()).1 }, //why the ::?
Int(vec) => unsafe { (vec.align_to::<u8>()).1 },
}
}
}
This works ok. However, if I rewrite the match with an or pipe:
impl Column {
fn as_bytes_succinct(&mut self) -> &[u8] {
use Column::*;
match self {
Short(vec) | Int(vec) => unsafe { (vec.align_to::<u8>()).1 },
}
}
}
I get
expected
i16
, foundi32
How/Why is the brief writing different from the explicit one?