From 8ec7bd2b3814fdd80a12d288c67076c5939d0756 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Tue, 19 Sep 2023 17:47:41 +0200 Subject: [PATCH] working bool dump --- Cargo.lock | 4 ++++ Cargo.toml | 6 ++++-- members/what-is/Cargo.toml | 8 +++++++ members/what-is/src/main.rs | 42 +++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 members/what-is/Cargo.toml create mode 100644 members/what-is/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 366b039..b4b6dbb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,3 +34,7 @@ checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" [[package]] name = "rs-unsafe" version = "0.1.0" + +[[package]] +name = "what-is" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index ee65c64..a264c46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,13 @@ [workspace] members = [ ".", - "members/c-bindings" + "members/c-bindings", + "members/what-is", ] default-members = [ ".", - "members/c-bindings" + "members/c-bindings", + "members/what-is", ] [package] diff --git a/members/what-is/Cargo.toml b/members/what-is/Cargo.toml new file mode 100644 index 0000000..d7d42f4 --- /dev/null +++ b/members/what-is/Cargo.toml @@ -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] diff --git a/members/what-is/src/main.rs b/members/what-is/src/main.rs new file mode 100644 index 0000000..a50ff5c --- /dev/null +++ b/members/what-is/src/main.rs @@ -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() { + println!("{:?}", TypeId::of::()); + 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, + ); + } + } +}