Expand description
Marker types for passing constants as type arguments.
§Example
This example emulates specialization,
eliding a .clone() call when the created array is only one element long.
use typewit::{const_marker::Usize, TypeCmp, TypeEq};
let arr = [3u8, 5, 8];
assert_eq!(repeat(3), []);
assert_eq!(repeat(3), [3]);
assert_eq!(repeat(3), [3, 3]);
assert_eq!(repeat(3), [3, 3, 3]);
assert_eq!(repeat(3), [3, 3, 3, 3]);
fn repeat<T: Clone, const OUT: usize>(val: T) -> [T; OUT] {
// `te_len` ìs a `TypeEq<Usize<OUT>, Usize<1>>`
if let TypeCmp::Eq(te_len) = Usize::<OUT>.equals(Usize::<1>) {
// This branch is ran when `OUT == 1`
TypeEq::new::<T>() // returns `TypeEq<T, T>`
.in_array(te_len) // returns `TypeEq<[T; OUT], [T; 1]>`
.to_left([val]) // goes from `[T; 1]` to `[T; OUT]`
} else {
// This branch is ran when `OUT != 1`
[(); OUT].map(|_| val.clone())
}
}Modules§
- slice
adt_const_marker - Marker types for
const FOO: &'static [T]parameters.
Structs§
- Bool
- Marker type for passing
const VAL: boolas a type parameter. - Char
- Marker type for passing
const VAL: charas a type parameter. - I8
- Marker type for passing
const VAL: i8as a type parameter. - I16
- Marker type for passing
const VAL: i16as a type parameter. - I32
- Marker type for passing
const VAL: i32as a type parameter. - I64
- Marker type for passing
const VAL: i64as a type parameter. - I128
- Marker type for passing
const VAL: i128as a type parameter. - Isize
- Marker type for passing
const VAL: isizeas a type parameter. - StdType
Equality rust_1_83 ConstMarkerfor getting whetherLandR(twoConstMarkerOf<StdType>) are the same type or not.- Str
adt_const_marker - Marker type for passing
const VAL: &'static stras a type parameter. - U8
- Marker type for passing
const VAL: u8as a type parameter. - U16
- Marker type for passing
const VAL: u16as a type parameter. - U32
- Marker type for passing
const VAL: u32as a type parameter. - U64
- Marker type for passing
const VAL: u64as a type parameter. - U128
- Marker type for passing
const VAL: u128as a type parameter. - Usize
- Marker type for passing
const VAL: usizeas a type parameter.
Enums§
Traits§
- Const
Marker - A type that represents a constant
- Const
Marker Eq rust_1_83 - A
ConstMarkerthat can be compared to anotherConstMarkerto produce aTypeCmpof the comparison. - Const
Marker EqOf rust_1_83 - Trait alias for
ConstMarkerEq<Of = Of> - Const
Marker HasWitness rust_1_83 - For getting the type witness of this
ConstMarker. - Const
Marker Of - Trait alias for
ConstMarker<Of = Of> - HasConst
Marker rust_1_83 - For types whose values have a
ConstMarkerequivalent.
Functions§
- equals
rust_1_83 - Compared any two
ConstMarkerEqtypes that have constants of the same type, returning a proof of their type (in)equality.
Type Aliases§
- BoolWit
- Type Witness that
Bool<B>is eitherBool<true>orBool<false>. - CmEquals
rust_1_83 - Type alias for
<Lhs as ConstMarkerEq>::Equals::<Rhs>, aConstMarker<Of = TypeCmp<Lhs, Rhs>>.