3 releases
Uses new Rust 2024
| 0.1.2 | Sep 23, 2025 |
|---|---|
| 0.1.1 | Aug 29, 2025 |
| 0.1.0 | Aug 29, 2025 |
#1327 in Embedded development
149 downloads per month
7KB
104 lines
Region — Fixed‑Size Typed Memory Access for 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.
Features
#![no_std]compatible- Compile‑time fixed capacity
- Runtime bounds & alignment checks
- Simple API for typed load/store
Example (no_std)
#![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 {}
}