Expand description
This module defines a types to encode an IF test within the type system.
The idea behind this concept is to match the condition, which is a type, with the structure the test is implemented for. This allows for a basic test similar to the following
let result = std::any::TypeId::of::<i32>() == std::any::TypeId::of::<i32>();
if result {
// Condition matched
} else {
// Condition failed to match
}
Example
use ct_utils::prelude::*;
// Trait to negate the signed-ness of a specific integer.
trait DeSignature<Target> {
type Result: ?Sized;
}
impl<Target> DeSignature<Target> for i32 {
// Depending on Target, CTIf::Path will become signed or unsigned.
// Result will receive the type contained by CTIf::Path.
type Result = <IfCheck<i32> as CTIf<Target, u32, i32>>::Path;
}
Notes
- If the receiving type parameter is constrained, the generic
CTIf
causes compilation errors due to missing constraints. You have to create your own specialized implementation ofCTIf
, which is made easy by utilizing the macroctif_specialize
.
Structs
Actual type used to perform an IF check through the type system.