Macro kernel::static_buf

source ·
macro_rules! static_buf {
    ($T:ty $(,)?) => { ... };
}
Expand description

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 StaticUninitializedBuffer 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_buf!(T);
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.