@jmst One thing that came out during the preparation of the portable SIMD vectors RFC is that a safe Compatible<T> would probably need to produce the same results in both little endian and big endian platforms.
That is, currently unsafe { mem::transmute } produces this behavior (playground):
let x: [i8; 16] = [
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15
];
let t: [i16; 8] = unsafe { mem::transmute(x) };
if cfg!(target_endian = "little") {
let t_el: [i16; 8] = [256, 770, 1284, 1798, 2312, 2826, 3340, 3854];
assert_eq!(t, t_el); // OK on LE
} else if cfg!(target_endian = "big") {
let t_be: [i16; 8] = [1, 515, 1029, 1543, 2057, 2571, 3085, 3599];
assert_eq!(t, t_be); // OK on BE
}
It would be nice if a safe_transmute operation could produce the same result in both architectures:
let x: [i8; 16] = [
0, 1, 2, 3, 4, 5, 6, 7
8, 9, 10, 11, 12, 13, 14, 15
];
let t: [i16; 8] = safe_transmute(x);
let el: [i16; 8] = [???];
assert_eq!(t, e); // OK on LE and on BE
Maybe this might not only be nice, but actually a necessary condition to make safe_transmute safe.
AFAIK the only way to achieve this would be to swap bytes inside safe_transmute on either little endian or big endian architectures.