cluFullTransmute

Crates.iocluFullTransmute
lib.rscluFullTransmute
version
sourcesrc
created_at2019-08-30 19:12:15.334215+00
updated_at2025-04-15 23:01:10.936314+00
descriptionA more complete and extended version of data type conversion without constraint checks.
homepage
repositoryhttps://github.com/clucompany/cluFullTransmute.git
max_upload_size
id160984
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Denis Kotlyarov (denisandroid)

documentation

README

!!! 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.3.1"

and this to your source code:

use cluFullTransmute::mem::transmute;

Example

use cluFullTransmute::transmute_or_panic;
use core::fmt::Display;

/*
	For example, let's write some code with a Drop trait that panics when dropped and
	holds some data. We then transmute this data to another similar struct and check
	that we have effectively overridden the Drop trait and have a different struct
	with some data.

	We can also remove the Drop trait altogether or do any number of other things.
*/

/// Struct to panic when dropped
#[derive(Debug)]
#[repr(transparent)]
struct PanicWhenDrop<T>(T);

impl<T> Drop for PanicWhenDrop<T> {
	fn drop(&mut self) {
		panic!("panic, discovered `drop(PanicWhenDrop);`");
	}
}

/// Struct to print value when dropped
#[derive(Debug)]
#[repr(transparent)]
struct PrintlnWhenDrop<T: Display>(T)
where
	T: Display;

impl<T> Drop for PrintlnWhenDrop<T>
where
	T: Display,
{
	fn drop(&mut self) {
		println!("println: {}", self.0);
	}
}

fn main() {
	let a: PanicWhenDrop<u16> = PanicWhenDrop(1024);
	println!("in a: {:?}", a);

	let b: PrintlnWhenDrop<u16> = unsafe { transmute_or_panic(a as PanicWhenDrop<u16>) };
	println!("out b: {:?}", b);

	drop(b); // <--- drop, PrintlnWhenDrop!
}
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.



Commit count: 38

cargo fmt