Trait r3::kernel::cfg::KernelStatic

source ·
pub trait KernelStatic<System = Self>: CfgPhase2<System> { }
Expand description

Associates static data to a system type.

The members of this trait are implementation details and not meant to be used externally. Use attach_phase3! or DelegateKernelStatic to implement this trait.

Derivation and Usage

This is one of the traits implemented by the kernel-independent configuration process. This process is divided into three phases. The first phase involves the following steps, mostly happening in a macro-generated function (let’s call this do_cfg_phase1):

  • do_cfg_phase1 constructs a C: const CfgBase and binds it to a local variable c.
  • do_cfg_phase1 invokes cfg_phase1!, passing &mut c, to construct and bind a Cfg<C> to a local variable b.
  • do_cfg_phase1 invokes an application-provided configuration function to register objects through b.
  • do_cfg_phase1 calls Cfg::finish_phase1 to obtain a CfgPhase1Data.
  • do_cfg_phase1 returns this CfgPhase1Data.
  • Using this CfgPhase1Data, attach_phase1! produces static items and an implementation of CfgPhase1 for C::System (directly or indirectly through DelegateKernelStatic).

The remaining phases repeat these steps using the prospective macros and functions as well as the constant values derived so far (through the implemented traits), each time recreating C and Cfg<C> from scratch. The final phase produces the finalized C, which the kernel-specific configuration process can use to complete the rest of the configuration process. (Cs produced by other phases are incomplete and therefore should be disregarded.) The final phase also produces an implementation of KernelStatic for C::System.

Rationale: Usually const fns can’t use constant values derived by themselves as constant values, but splitting into multiple phases makes this possible.

The current implementation doesn’t fully utilize all of the three phases. The extra phases are kept to leave room for future internal changes.

The following diagram outlines the data flow in this process.

Implementors§

source§

impl<T, System> KernelStatic<System> for Twhere T: DelegateKernelStatic<System>, <T as DelegateKernelStatic<System>>::Target: KernelStatic<System>,