expression

Represent configured pin modes using types

A HAL can use types to represent configured states so operations are offered only in appropriate modes. This no_std model uses a consuming mode transition and a zero-sized state marker. No registers are touched; actual mode changes must follow the device reference manual and electrical constraints. Expected host stdout (not executed): output level: true Common mistake: Assuming a type-level mode transition itself changes physical hardware, or duplicating the token.

Formal Syntax & Structure

rust syntaxrust
Pin<Input> → Pin<Output>

Working Example

Example Snippetrust
#![no_std]use core::marker::PhantomData;pub struct Input;pub struct Output;pub struct Pin<Mode> { level: bool, mode: PhantomData<Mode> }impl Pin<Input> {    pub fn simulated() -> Self { Self { level: false, mode: PhantomData } }    pub fn into_output(self) -> Pin<Output> { Pin { level: self.level, mode: PhantomData } }}impl Pin<Output> {    pub fn set_high(&mut self) { self.level = true; }    pub fn level(&self) -> bool { self.level }}
Rust Reference