expression
Validate multidimensional array shapes
A shape specifies the length of each axis. A contiguous rectangular buffer must have the product of those lengths as its element count. Check multiplication before allocation or indexing. Zero-length axes are permitted in this model; real allocations also have byte-size constraints. Expected result (NOT RUN): 2x3: true, 3x3: false overflow rejected: true Common mistake: Checking shape only after unchecked multiplication or assuming shape describes storage order. Static Rust example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
rows.checked_mul(cols) == Some(data.len())Working Example
Example Snippetrust
fn valid(rows: usize, cols: usize, data: &[i32]) -> bool { rows.checked_mul(cols) == Some(data.len())}fn main() { let data = [1, 2, 3, 4, 5, 6]; println!("2x3: {}, 3x3: {}", valid(2, 3, &data), valid(3, 3, &data)); println!("overflow rejected: {}", !valid(usize::MAX, 2, &data));}