cluFullTransmute

Build Status Apache licensed crates.io Documentation

A more complete and advanced version of data transmutation without restrictions.

Opportunities

  1. Casting any type A to any type B without checking the dimensionality of the data.
  2. The ability to use transmutation in constant functions.
  3. Possibility of delayed transmutation.
  4. Possibility of work in #![no_std]

Attention!

  1. You really need to understand what you are doing.

Use

1. GenericType

```rust use cluFullTransmute::mem::full_transmute;

struct A(T);

impl Drop for A { fn drop(&mut self) { panic!("Strange behavior of the internal library."); } }

struct B(T);

impl B { pub fn my_fn(&self) {} }

fn main() { let data = A(9999usize); //ignore drop!

let b: B<usize> = unsafe { full_transmute(data) };
assert_eq!(b.0, 9999);

b.my_fn();

} ```

2. Easy

```rust use cluFullTransmute::mem::full_transmute;

fn main() { let a: bool = unsafe { fulltransmute(1u8) }; asserteq!(a, true);

let b: bool = unsafe { full_transmute(0u8) };
assert_eq!(b, false);

// Why does this work?
//
// Is bool one bit?
// No, bool is not one bit, but u8.
//
assert_eq!(std::mem::size_of::<bool>(), 1);

} ```

3. MaybeTransmute

```rust use cluFullTransmute::mem::MaybeTransmute;

struct MyData { data: MaybeTransmute>, }

impl MyData { #[inline] pub fn new>(t: I) -> Self { Self::__new(t.into()) }

#[inline]
const fn __new(data: String) -> Self {
    let data = unsafe {
        MaybeTransmute::new(data)
    };

    Self {
        data
    }   
}

#[inline]
pub fn as_string(&mut self) -> &mut String {
    &mut self.data
}

#[inline]
pub fn into(self) -> Vec<u8> {
    self.data.into()
}

}

fn main() { let mut data = MyData::new("Test"); asserteq!(data.asstring().asbytes(), b"Test"); asserteq!(data.as_string(), "Test");

let vec = data.into();
assert_eq!(vec, b"Test");

} ```

License

Copyright 2021 #UlinProject Denis Kotlyarov (Денис Котляров)

Licensed under the Apache License, Version 2.0