kernel

Macro TIfCfg

Source
macro_rules! TIfCfg {
    ($feature : ident, $TIf : ty, $TElse : ty) => { ... };
    ($feature : ident, $T : ty) => { ... };
}
Expand description

Correctly uses the IfElseCfg type depending on one of the config options in the global CONFIG struct. If no false type is provided, it will be unit.

Usage: type MyType = TIfCfg!(FeatureFlag, TrueType [, FalseType]?);

e.g.:

type TracingType = TIfCfg!(trace_syscalls, TypeNeedIfTracing);

Expands to

type TracingType = IfElseCfg<TypeNeedIfTracing, (), {(CONFIG.trace_syscalls) as usize}>

Usage in conjunction with ! (or never::Never),

If you want to eliminate a enum variant in certain configurations, do:

See OnlyInCfg and NotInCfg for shorter forms

use kernel::TIfCfg;
use kernel::utilities::never::Never;
enum E {
  Var1,
  Var2(TIfCfg!(debug_panics, (), Never)), // variant only exists with config debug_panics
  Var3(TIfCfg!(debug_panics, Never, ())), // variant only exists without config debug_panics
}