working bool dump

This commit is contained in:
Christoph J. Scherr 2023-09-19 17:47:41 +02:00
parent 3cf32c5a2f
commit 8ec7bd2b38
4 changed files with 58 additions and 2 deletions

4
Cargo.lock generated
View File

@ -34,3 +34,7 @@ checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b"
[[package]] [[package]]
name = "rs-unsafe" name = "rs-unsafe"
version = "0.1.0" version = "0.1.0"
[[package]]
name = "what-is"
version = "0.1.0"

View File

@ -1,11 +1,13 @@
[workspace] [workspace]
members = [ members = [
".", ".",
"members/c-bindings" "members/c-bindings",
"members/what-is",
] ]
default-members = [ default-members = [
".", ".",
"members/c-bindings" "members/c-bindings",
"members/what-is",
] ]
[package] [package]

View File

@ -0,0 +1,8 @@
[package]
name = "what-is"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -0,0 +1,42 @@
use std::any::{TypeId, type_name};
//* # See what's behind the primitive datatypes of Rust
//*
//* This Crate shows off, how primitive Types of rust are stored in memory.
fn main() {
println!("bool");
let mut items = Vec::new();
items.push(true);
items.push(false);
unsafe {
for (index, item) in items.iter().enumerate() {
let mem_item: [u8; 1] = std::mem::transmute(*item);
let ref_item: [u8; 8] = std::mem::transmute(item);
println!("\t{index:02x}\titem:\t{item}\n\
\t\tmemory: {:X?}\n\n\
\t\tlocal ref: {:X?}",
mem_item,
ref_item,
);
}
}
}
fn dump_type<T: 'static>() {
println!("{:?}", TypeId::of::<T>());
let mut items = Vec::new();
items.push(true);
items.push(false);
unsafe {
for (index, item) in items.iter().enumerate() {
let mem_item: [u8; 1] = std::mem::transmute(*item);
let ref_item: [u8; 8] = std::mem::transmute(item);
println!("\t{index:02x}\titem:\t{item}\n\
\t\tmemory: {:X?}\n\n\
\t\tlocal ref: {:X?}",
mem_item,
ref_item,
);
}
}
}