How can I implement a generic function in Rust in a way that can convert a generic type T
(u16
, u32
, or u64
) into a Vec<u8>
using either little-endian or big-endian formats.
E.g. (not valid Rust code):
fn convert<T>(a: T) -> vec<u8> {
// a = 0x01234567
// returns vec![0x01, 0x23, 0x45, 0x67]
}