Macro kernel::static_named_buf
source · macro_rules! static_named_buf { ($T:ty, $N:expr $(,)?) => { ... }; }
Expand description
A version of static_buf!()
that adds an exported name to the buffer.
This creates a static buffer exactly as static_buf!()
does. In general,
most uses should use static_buf!()
. However, in cases where the symbol
name of the buffer matters, this version is useful.
Allocates a statically-sized global region of memory for data structures but does not initialize the memory. Checks that the buffer is not aliased and is only used once.
This macro creates the static buffer, and returns a
core::mem::MaybeUninit
wrapper containing the buffer. The memory is
allocated, but it is guaranteed to be uninitialized inside of the wrapper.
Before the static buffer can be used it must be initialized. For example:
let mut static_buffer = static_nmaed_buf!(T, "MY_BUF");
let static_reference: &'static mut T = static_buffer.initialize(T::new());
Separating the creation of the static buffer into its own macro is not strictly necessary, but it allows for more flexibility in Rust when boards are initialized and the static structures are being created. Since creating and initializing static buffers requires knowing the particular types (and their sizes), writing shared initialization code (in components for example) where the types are unknown since they vary across boards is difficult. By splitting buffer creating from initialization, creating shared components is possible.