[clufulltransmute]
( Extended, no-constraint type transmutation API, featuring safe checks and const-ready logic. )
- When converting types without checking the size of the data, you really need to understand what you are doing.
- You must understand the specifics of the platform you are using.
- Casting any type A to any type B with generic data without and with data dimension checking.
- Ability to use transmutation in constant functions in very old versions of rust.
- Possibility of delayed transmutation through contracts.
- Ability to work without the standard library.
Add this to your Cargo.toml:
[dependencies]
cluFullTransmute = "1.4.1"
and this to your source code:
use cluFullTransmute::try_transmute;
use cluFullTransmute::try_transmute_or_panic;
use cluFullTransmute::transmute_unchecked;
Purpose: Combines two arrays of the same size [T; N]
into a single fixed-length array [T; N*2]
.
use cluFullTransmute::try_transmute_or_panic;
pub const fn concat_arrays<T, const N: usize, const NDOUBLE: usize>(
a: [T; N],
b: [T; N],
) -> [T; NDOUBLE] {
#[repr(C)]
struct Pair<T, const N: usize> {
a: [T; N],
b: [T; N],
}
unsafe { try_transmute_or_panic(Pair { a, b }) }
}
fn main() {
const A: [u8; 4] = [1, 2, 3, 4];
const B: [u8; 4] = [5, 6, 7, 8];
const C: [u8; 8] = concat_arrays(A, B);
println!("{C:?}"); // [1, 2, 3, 4, 5, 6, 7, 8]
}
This project has a single license (LICENSE-APACHE-2.0).