expression

Distinguish a DMA request from confirmed completion

A requested abort is not proof that the DMA engine stopped accessing memory. This state machine permits buffer reuse only after a modeled hardware stop or normal completion. Its transitions are illustrative and do not read any actual hardware flags. On a real target confirm completion or quiescence using the device manual and correct memory synchronization. Expected host stdout (not executed): after request: false after confirmation: true Common mistake: Reusing a buffer immediately after requesting cancellation.

Formal Syntax & Structure

rust syntaxrust
enum TransferState { Idle, Active, CancelRequested, Complete }

Working Example

Example Snippetrust
#![no_std]#[derive(Clone, Copy)]pub enum State { Idle, Active, CancelRequested, Complete }impl State {    pub fn reusable(self) -> bool { matches!(self, Self::Idle | Self::Complete) }    pub fn cancel(self) -> Self { match self { Self::Active => Self::CancelRequested, s => s } }}
Rust Reference