[go: up one dir, main page]

Module const_marker

Module const_marker 

Source
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§

sliceadt_const_marker
Marker types for const FOO: &'static [T] parameters.

Structs§

Bool
Marker type for passing const VAL: bool as a type parameter.
Char
Marker type for passing const VAL: char as a type parameter.
I8
Marker type for passing const VAL: i8 as a type parameter.
I16
Marker type for passing const VAL: i16 as a type parameter.
I32
Marker type for passing const VAL: i32 as a type parameter.
I64
Marker type for passing const VAL: i64 as a type parameter.
I128
Marker type for passing const VAL: i128 as a type parameter.
Isize
Marker type for passing const VAL: isize as a type parameter.
StdTypeEqualityrust_1_83
ConstMarker for getting whether L and R (two ConstMarkerOf<StdType>) are the same type or not.
Stradt_const_marker
Marker type for passing const VAL: &'static str as a type parameter.
U8
Marker type for passing const VAL: u8 as a type parameter.
U16
Marker type for passing const VAL: u16 as a type parameter.
U32
Marker type for passing const VAL: u32 as a type parameter.
U64
Marker type for passing const VAL: u64 as a type parameter.
U128
Marker type for passing const VAL: u128 as a type parameter.
Usize
Marker type for passing const VAL: usize as a type parameter.

Enums§

BoolWitG
Type witness that B is either Bool<true> or Bool<false>

Traits§

ConstMarker
A type that represents a constant
ConstMarkerEqrust_1_83
A ConstMarker that can be compared to another ConstMarker to produce a TypeCmp of the comparison.
ConstMarkerEqOfrust_1_83
Trait alias for ConstMarkerEq<Of = Of>
ConstMarkerHasWitnessrust_1_83
For getting the type witness of this ConstMarker.
ConstMarkerOf
Trait alias for ConstMarker<Of = Of>
HasConstMarkerrust_1_83
For types whose values have a ConstMarker equivalent.

Functions§

equalsrust_1_83
Compared any two ConstMarkerEq types that have constants of the same type, returning a proof of their type (in)equality.

Type Aliases§

BoolWit
Type Witness that Bool<B> is either Bool<true> or Bool<false>.
CmEqualsrust_1_83
Type alias for <Lhs as ConstMarkerEq>::Equals::<Rhs>, a ConstMarker<Of = TypeCmp<Lhs, Rhs>>.