macro_rules! make_static {
    ($val:expr) => { ... };
    ($val:expr, $(#[$m:meta])*) => { ... };
}
Available on crate feature nightly only.
Expand description

Convert a T to a &'static mut T.

The macro declares a static StaticCell and then initializes it when run, returning the &'static mut. Therefore, each instance can only be run once. Next runs will panic. The static can additionally be decorated with attributes, such as #[link_section], #[used], et al.

This macro is nightly-only. It requires #![feature(type_alias_impl_trait)] in the crate using it.

Examples

use static_cell::make_static;

let x: &'static mut u32 = make_static!(42);

// This attribute instructs the linker to allocate it in the external RAM's BSS segment.
// This specific example is for ESP32S3 with PSRAM support.
let buf = make_static!([0u8; 4096], #[link_section = ".ext_ram.bss.buf"]);

// Multiple attributes can be supplied.
let s = make_static!(0usize, #[used] #[export_name = "exported_symbol_name"]);