Crates.io | memprint |
lib.rs | memprint |
version | 0.1.1 |
source | src |
created_at | 2024-08-18 19:34:37.262453 |
updated_at | 2024-08-18 20:16:38.546591 |
description | A way to print memory layout of a struct |
homepage | |
repository | https://github.com/slbsh/memprint |
max_upload_size | |
id | 1342908 |
size | 37,759 |
memprint provides a single MemPrint
trait (including a derive macro for it!),
which allows you to print the underlying memory layout of a type.
here are the two ways ye can use your newfound powers:
use memprint::MemPrint;
#[derive(MemPrint)]
struct MyStruct {
c: u8,
a: i32,
b: f32,
}
impl MyStruct {
fn new(a: i32, b: f32, c: u8) -> Self {
Self { a, b, c }
}
}
fn main() {
let struc = MyStruct::new(42, 3.14, b'A');
// provides a detailed printout of a single struct
MyStruct::memprint(&struc);
let mut vec = Vec::new();
vec.push(MyStruct::new(42, 3.14, b'A'));
vec.push(MyStruct::new(69, 2.71, b'B'));
vec.push(MyStruct::new(1337, 1.41, b'C'));
vec.push(MyStruct::new(9001, 0.0, b'D'));
vec.push(MyStruct::new(80085, -1.0, b'E'));
println!("\n\n");
// prints a colour coded block of memory, representing the elements of the slice
MyStruct::memprint_block(&vec);
}