expression

Model DMA buffer ownership across a transfer

DMA (direct memory access) lets a peripheral transfer data without the CPU copying each byte. While a real DMA engine owns a receive buffer, the CPU must not access the affected region. This purely synchronous type-state model moves an array between states; it never exposes an address to hardware. Real drivers require stable DMA-accessible storage, leak-safe ownership and hardware-specific completion and cache rules. Expected host stdout (not executed): data Common mistake: Using this movable array model as an actual asynchronous DMA buffer, or relying only on Drop to prevent hardware access after storage is freed.

Formal Syntax & Structure

rust syntaxrust
Ready::start(self) -> Busy; Busy::finish(self) -> Ready

Working Example

Example Snippetrust
#![no_std]pub struct Ready([u8; 4]);pub struct Busy([u8; 4]);impl Ready {    pub fn new() -> Self { Self([0; 4]) }    pub fn start(self) -> Busy { Busy(self.0) }    pub fn bytes(&self) -> &[u8] { &self.0 }}impl Busy {    pub fn finish(mut self) -> Ready {        self.0.copy_from_slice(b"data"); // simulated completion only        Ready(self.0)    }}
Rust Reference