expression
Use alloc when dynamic allocation is available
The alloc crate provides owned heap-backed containers without requiring the full std library. The final executable needs an appropriate allocator and allocation-failure policy when allocation is used. This library returns a Vec; the desktop harness supplies the ordinary std allocator. A successful host build would not prove that a bare-metal allocator exists. Expected host stdout (not executed): [4, 10, 510] Common mistake: Assuming extern crate alloc installs a heap or that Vec is provided by core.
Formal Syntax & Structure
rust syntaxrust
extern crate alloc; use alloc::vec::Vec;Working Example
Example Snippetrust
#![no_std]extern crate alloc;use alloc::vec::Vec;pub fn scaled(input: &[u8]) -> Vec<u16> { input.iter().map(|&n| u16::from(n) * 2).collect()}