[][src]Type Definition core_extensions::type_level_bool::IfElse

type IfElse<Cond, Then, Else> = <IfElseOp<Cond, Then, Else> as BooleanOp>::Value;

Type level conditional.

if Cond==True the type is Then.

if Cond==False the type is Else.

This will be more ergonomic once specialization is stable.


use core_extensions::type_level_bool::{IfElse,True,False};
let a:IfElse<True ,i32,&str>=0;
let b:IfElse<False,i32,&str>="type level conditionals";

Example of field whose type depends on a Boolean.

Currently it is necessary to add a where clause to the type containing a conditional field, this limitation will be lifted once specialization is stable.

use core_extensions::VariantPhantom;
use core_extensions::type_level_bool::{IfElse,Boolean,False,True};
use core_extensions::type_level_bool::internals::{IfElseOp,BooleanOp};

struct Conditional<ZST>
    IfElseOp<ZST,&'static str,usize>:BooleanOp,
    pub value:IfElse<ZST,&'static str,usize>,
    pub cond:ZST,

let string_=Conditional{ value:"wtf" ,cond:True  };
let int_   =Conditional{ value:99    ,cond:False };

// The 2 lines bellow won't compile.
// let string_=Conditional{ value:"wtf",cond:False };
// let int_   =Conditional{ value:99   ,cond:True };