pub trait DelegateKernelStatic<System> {
    type Target;
}
Expand description

The marker trait to generate a forwarding implementation of KernelStatic<System> as well as CfgPhase1<System> and CfgPhase2<System>.

This is useful for circumventing the orphan rules. Suppose we have a kernel crate r3_kernel and an application crate app, and r3_kernel provides a system type System<Traits>, where Traits is a marker type to be defined in an application crate. For many reasons, static items to store a kernel state can only be defined in app, where the concrete form of the kernel is known. This means impl KernelStatic for System<Traits> has to appear in app, but since both KernelStatic and System are foreign to app, this is not allowed by the orphan rules.

// r3::kernel::cfg
// ========================
trait KernelStatic<System> {}

// r3_kernel
// ========================
struct System<Traits> { /* ... */ }

// app
// ========================
struct Traits;
impl r3::kernel::cfg::KernelStatic<r3_kernel::System<Traits>>
    for r3_kernel::System<Traits> {} // E0117

The above example can be fixed by implementing KernelStatic on Traits instead and DelegateKernelStatic on System.

// r3::kernel::cfg
// ========================
trait KernelStatic<System> {}
trait DelegateKernelStatic<System> { type Target; }
impl<T, System> KernelStatic<System> for T
    where T: DelegateKernelStatic<System> {}

// r3_kernel
// ========================
struct System<Traits> { /* ... */ }
impl<Traits> DelegateKernelStatic for System<Traits> {
    // Inherit `Traits`'s implementation
    type Target = Traits;
}

// app
// ========================
struct Traits;
impl r3::kernel::cfg::KernelStatic<r3_kernel::System<Traits>>
    for Traits {} // OK

Required Associated Types§

Implementors§