static_memory_rs

Crates.iostatic_memory_rs
lib.rsstatic_memory_rs
version0.1.2
created_at2025-08-29 00:18:38.004374+00
updated_at2025-09-23 21:51:29.683318+00
descriptionA 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
id1814950
size6,986
(WebAppEnjoyer)

documentation

README

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 {}
}
Commit count: 0

cargo fmt