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>
impl<T, U, const COND: bool> IfElseCfg<T, U, COND>
pub fn unwrap(self) -> <(*const T, *const U) as CfgControl<CONDITION>>::Out
pub fn unwrap_ref( &self, ) -> &<(*const T, *const U) as CfgControl<CONDITION>>::Out
pub fn unwrap_mut( &mut self, ) -> &mut <(*const T, *const U) as CfgControl<CONDITION>>::Out
Source§impl<T, U> IfElseCfg<T, U, true>
impl<T, U> IfElseCfg<T, U, true>
pub const fn new_true(value: T) -> Self
pub const fn new_false(_value: U) -> Self
pub const fn new(value_true: T, _value_false: U) -> Self
pub fn get_match(&self) -> CfgMatch<'_, T, U>
pub fn get_match_mut(&mut self) -> CfgMatchMut<'_, T, U>
pub fn map_ref<R, FT, FF>(&self, true_f: FT, _false_f: FF) -> R
pub fn map_mut<R, FT, FF>(&mut self, true_f: FT, _false_f: FF) -> R
pub const fn get_true_ref(&self) -> &T
pub fn get_true_mut(&mut self) -> &mut T
pub fn get_false_ref(&self) -> &U
pub fn get_false_mut(&mut self) -> &mut U
pub fn consume_true(self) -> T
pub fn consume_false(self) -> U
pub fn consume(self) -> CfgConsumed<T, U>
pub fn cfg_into<X>(self) -> X
pub fn cfg_from<X: Into<T> + Into<U>>(x: X) -> Self
Source§impl<T, U> IfElseCfg<T, U, false>
impl<T, U> IfElseCfg<T, U, false>
pub const fn new_true(_value: T) -> Self
pub const fn new_false(value: U) -> Self
pub const fn new(_value_true: T, value_false: U) -> Self
pub fn get_match(&self) -> CfgMatch<'_, T, U>
pub fn get_match_mut(&mut self) -> CfgMatchMut<'_, T, U>
pub fn map_ref<R, FT, FF>(&self, _true_f: FT, false_f: FF) -> R
pub fn map_mut<R, FT, FF>(&mut self, _true_f: FT, false_f: FF) -> R
pub fn get_true_ref(&self) -> &T
pub fn get_true_mut(&mut self) -> &mut T
pub const fn get_false_ref(&self) -> &U
pub fn get_false_mut(&mut self) -> &mut U
pub fn consume_true(self) -> T
pub fn consume_false(self) -> U
pub fn consume(self) -> CfgConsumed<T, U>
pub fn cfg_into<X>(self) -> X
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,
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§impl<T: Ord, U: Ord> Ord for IfElseCfg<T, U, false>
impl<T: Ord, U: Ord> Ord for IfElseCfg<T, U, false>
Source§impl<T: Ord, U: Ord> Ord for IfElseCfg<T, U, true>
impl<T: Ord, U: Ord> Ord for IfElseCfg<T, U, true>
Source§impl<T: PartialOrd, U: PartialOrd> PartialOrd for IfElseCfg<T, U, false>
impl<T: PartialOrd, U: PartialOrd> PartialOrd for IfElseCfg<T, U, false>
Source§impl<T: PartialOrd, U: PartialOrd> PartialOrd for IfElseCfg<T, U, true>
impl<T: PartialOrd, U: PartialOrd> PartialOrd for IfElseCfg<T, U, true>
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,
impl<T: Eq, U: Eq> Eq for IfElseCfg<T, U, false>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more