Crates.io | static_memory_rs |
lib.rs | static_memory_rs |
version | 0.1.2 |
created_at | 2025-08-29 00:18:38.004374+00 |
updated_at | 2025-09-23 21:51:29.683318+00 |
description | A fixed-capacity, no_std-friendly memory region with typed read/write access, runtime bounds checks, and alignment verification — ideal for embedded and systems programming. |
homepage | |
repository | |
max_upload_size | |
id | 1814950 |
size | 6,986 |
no_std
A small, panic‑checked static memory region that provides safe, typed reads and writes with runtime bounds and alignment verification.
Useful in no_std
and embedded contexts where you need manual layout control without the unpredictability of the global allocator.
#![no_std]
compatible#![no_std]
#![no_main]
use core::mem::{align_of, size_of};
use my_region_crate::Region;
#[repr(C)]
#[derive(Copy, Clone, Debug)]
struct Header {
id: u32,
flags: u16,
}
#[no_mangle]
pub extern "C" fn main() -> ! {
let mut reg: Region<64> = Region::new();
// Safe write — offset is aligned to 4 for u32
reg.write::<u32>(0, 0xDEADBEEF);
// Safe write — offset is aligned to 4 (Header's max field align)
reg.write::<Header>(4, Header { id: 42, flags: 3 });
// Safe read back
let hdr: Header = reg.read::<Header>(4);
assert_eq!(hdr.id, 42);
loop {}
}