expression
Select a target-specific implementation before type checking
Embedded targets commonly have target_os="none". Conditional compilation can select a tiny target implementation while a hosted test uses a mock. The label is only a build-time distinction; it does not prove that the correct peripheral or board is present. Expected host stdout (not executed): host mock Common mistake: Using cfg! to hide unavailable imports, or using target_os as a board identifier.
Formal Syntax & Structure
rust syntaxrust
#[cfg(target_os = "none")]Working Example
Example Snippetrust
#![no_std]#[cfg(target_os = "none")]pub fn backend() -> &'static str { "bare-metal" }#[cfg(not(target_os = "none"))]pub fn backend() -> &'static str { "host mock" }