Skip to content

clucompany/cluFullTransmute

Repository files navigation

[clufulltransmute]

( Extended, no-constraint type transmutation API, featuring safe checks and const-ready logic. )

!!! ATTENTION

  1. When converting types without checking the size of the data, you really need to understand what you are doing.
  2. You must understand the specifics of the platform you are using.

Library features

  1. Casting any type A to any type B with generic data without and with data dimension checking.
  2. Ability to use transmutation in constant functions in very old versions of rust.
  3. Possibility of delayed transmutation through contracts.
  4. Ability to work without the standard library.

Usage

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;

Example

concat_arrays

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]
}
See all

License

This project has a single license (LICENSE-APACHE-2.0).

uproject  Copyright (c) 2019-2025 #UlinProject

 (Denis Kotlyarov).


Apache License

apache2  Licensed under the Apache License, Version 2.0.



About

[stable] Extended, no-constraint type transmutation API, featuring safe checks and const-ready logic.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages