std-module

Rust std::alloc module

Allocation APIs separate storage requests from the values placed in storage. Most Rust code should use Box or Vec; direct allocation requires explicit ownership bookkeeping. This example describes a request without allocating. Expected stdout (not executed): 6 bytes Common mistake: Mistaking a layout descriptor for an allocated buffer.

Formal Syntax & Structure

rust syntaxrust
use std::alloc::Layout;

Working Example

Example Snippetrust
#![deny(unsafe_op_in_unsafe_fn)]fn main() {    use std::alloc::Layout;    let request = Layout::new::<[u8; 6]>();    println!("{} bytes", request.size());}
Rust Reference