expression
Calculate a bounded buffer memory budget
Fixed-size arrays give a predictable element-storage requirement without requesting heap allocation. Static storage duration is a separate property: a local array is not automatically static. This budget function checks overflow and includes only byte payloads, not metadata, padding, stacks or linker overhead. Expected host stdout (not executed): two: Some(256) three: None Common mistake: Treating a payload calculation as a complete RAM budget or assuming fixed capacity implies static lifetime.
Formal Syntax & Structure
rust syntaxrust
count.checked_mul(bytes_per_buffer)Working Example
Example Snippetrust
#![no_std]pub fn budget(count: usize, bytes_per_buffer: usize, available: usize) -> Option<usize> { let bytes = count.checked_mul(bytes_per_buffer)?; (bytes <= available).then_some(bytes)}