kernel::config

Struct IfElseCfg

Source
pub struct IfElseCfg<T, U, const CONDITION: bool>(/* private fields */)
where
    (*const T, *const U): CfgControl<CONDITION>;
Expand description

These types are for situations where a feature would change what type is in use. This is better than conditional compilation as a single compilation run can type check all combinations of features.

Usage: type MyType = IfElseCfg<TrueType, FalseType, ConditionForTrueType>

If coming from C and you are used to the pattern of

struct Foo { #if SOME_FLAG T1 field_t1; #else T2 field_t2; #endif }

Instead write:

struct Foo { field : IfElseCfg<T1, T2, SOME_FLAG>, }

Then, rather than

Foo myFoo = …; #if SOME_FLAG bar(&myFoo.field_t1); #else baz(&myFoo.field_t2); #endif

Do

let myFoo : Foo = …; if SOME_FLAG { bar(myFoo.get_true_ref()) } else { baz(myFoo.get_false_ref()) }

Or more cleanly:

let myFoo : Foo = …; myFoo.mapRef(bar, baz);

Implementations§

Source§

impl<T, U, const COND: bool> IfElseCfg<T, U, COND>
where (*const T, *const U): CfgControl<COND>,

Source

pub fn unwrap(self) -> <(*const T, *const U) as CfgControl<CONDITION>>::Out
where <(*const T, *const U) as CfgControl<COND>>::Out: Sized,

Source

pub fn unwrap_ref( &self, ) -> &<(*const T, *const U) as CfgControl<CONDITION>>::Out

Source

pub fn unwrap_mut( &mut self, ) -> &mut <(*const T, *const U) as CfgControl<CONDITION>>::Out

Source§

impl<T, U> IfElseCfg<T, U, true>

Source

pub const fn new_true(value: T) -> Self

Source

pub const fn new_false(_value: U) -> Self

Source

pub const fn new(value_true: T, _value_false: U) -> Self
where T: Copy, U: Copy,

Source

pub fn get_match(&self) -> CfgMatch<'_, T, U>

Source

pub fn get_match_mut(&mut self) -> CfgMatchMut<'_, T, U>

Source

pub fn map_ref<R, FT, FF>(&self, true_f: FT, _false_f: FF) -> R
where FT: FnOnce(&T) -> R, FF: FnOnce(&U) -> R,

Source

pub fn map_mut<R, FT, FF>(&mut self, true_f: FT, _false_f: FF) -> R
where FT: FnOnce(&mut T) -> R, FF: FnOnce(&mut U) -> R,

Source

pub const fn get_true_ref(&self) -> &T

Source

pub fn get_true_mut(&mut self) -> &mut T

Source

pub fn get_false_ref(&self) -> &U

Source

pub fn get_false_mut(&mut self) -> &mut U

Source

pub fn consume_true(self) -> T

Source

pub fn consume_false(self) -> U

Source

pub fn consume(self) -> CfgConsumed<T, U>

Source

pub fn cfg_into<X>(self) -> X
where T: Into<X>, U: Into<X>,

Source

pub fn cfg_from<X: Into<T> + Into<U>>(x: X) -> Self

Source§

impl<T, U> IfElseCfg<T, U, false>

Source

pub const fn new_true(_value: T) -> Self

Source

pub const fn new_false(value: U) -> Self

Source

pub const fn new(_value_true: T, value_false: U) -> Self
where T: Copy, U: Copy,

Source

pub fn get_match(&self) -> CfgMatch<'_, T, U>

Source

pub fn get_match_mut(&mut self) -> CfgMatchMut<'_, T, U>

Source

pub fn map_ref<R, FT, FF>(&self, _true_f: FT, false_f: FF) -> R
where FT: FnOnce(&T) -> R, FF: FnOnce(&U) -> R,

Source

pub fn map_mut<R, FT, FF>(&mut self, _true_f: FT, false_f: FF) -> R
where FT: FnOnce(&mut T) -> R, FF: FnOnce(&mut U) -> R,

Source

pub fn get_true_ref(&self) -> &T

Source

pub fn get_true_mut(&mut self) -> &mut T

Source

pub const fn get_false_ref(&self) -> &U

Source

pub fn get_false_mut(&mut self) -> &mut U

Source

pub fn consume_true(self) -> T

Source

pub fn consume_false(self) -> U

Source

pub fn consume(self) -> CfgConsumed<T, U>

Source

pub fn cfg_into<X>(self) -> X
where T: Into<X>, U: Into<X>,

Source

pub fn cfg_from<X: Into<T> + Into<U>>(x: X) -> Self

Trait Implementations§

Source§

impl<T: Clone, U: Clone, const COND: bool> Clone for IfElseCfg<T, U, COND>
where (*const T, *const U): CfgControl<COND>, <(*const T, *const U) as CfgControl<CONDITION>>::Out: Clone,

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, U: Debug> Debug for IfElseCfg<T, U, false>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Debug, U: Debug> Debug for IfElseCfg<T, U, true>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default, U: Default> Default for IfElseCfg<T, U, false>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Default, U: Default> Default for IfElseCfg<T, U, true>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Display, U: Display> Display for IfElseCfg<T, U, false>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Display, U: Display> Display for IfElseCfg<T, U, true>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Hash, U: Hash> Hash for IfElseCfg<T, U, false>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Hash, U: Hash> Hash for IfElseCfg<T, U, true>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: LowerHex, U: LowerHex> LowerHex for IfElseCfg<T, U, false>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: LowerHex, U: LowerHex> LowerHex for IfElseCfg<T, U, true>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Ord, U: Ord> Ord for IfElseCfg<T, U, false>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: Ord, U: Ord> Ord for IfElseCfg<T, U, true>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq, U: PartialEq> PartialEq for IfElseCfg<T, U, false>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialEq, U: PartialEq> PartialEq for IfElseCfg<T, U, true>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd, U: PartialOrd> PartialOrd for IfElseCfg<T, U, false>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: PartialOrd, U: PartialOrd> PartialOrd for IfElseCfg<T, U, true>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: UpperHex, U: UpperHex> UpperHex for IfElseCfg<T, U, false>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: UpperHex, U: UpperHex> UpperHex for IfElseCfg<T, U, true>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Copy, U: Copy, const COND: bool> Copy for IfElseCfg<T, U, COND>
where (*const T, *const U): CfgControl<COND>, <(*const T, *const U) as CfgControl<CONDITION>>::Out: Copy,

Source§

impl<T: Eq, U: Eq> Eq for IfElseCfg<T, U, false>

Source§

impl<T: Eq, U: Eq> Eq for IfElseCfg<T, U, true>

Auto Trait Implementations§

§

impl<T, U, const CONDITION: bool> !Freeze for IfElseCfg<T, U, CONDITION>

§

impl<T, U, const CONDITION: bool> !RefUnwindSafe for IfElseCfg<T, U, CONDITION>

§

impl<T, U, const CONDITION: bool> !Send for IfElseCfg<T, U, CONDITION>

§

impl<T, U, const CONDITION: bool> !Sized for IfElseCfg<T, U, CONDITION>

§

impl<T, U, const CONDITION: bool> !Sync for IfElseCfg<T, U, CONDITION>

§

impl<T, U, const CONDITION: bool> !Unpin for IfElseCfg<T, U, CONDITION>

§

impl<T, U, const CONDITION: bool> !UnwindSafe for IfElseCfg<T, U, CONDITION>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.