frunk_core/
indices.rs

1//! Types used for indexing into HLists and coproducts.
2//!
3//! frunk frequently uses phantom index types as a technique to avoid
4//! overlapping impls for some traits.
5//!
6//! Currently, `Index` type parameters in traits are not ever really intended
7//! to be selected by the user, and are instead simply solved for by type
8//! inference wherever the compiler can see that there is a unique solution.
9//! Therefore, you don't really have much of a reason to use the things in this
10//! module.
11//!
12//! **...yet.** `;)`
13
14use core::marker::PhantomData;
15
16// Largely lifted from https://github.com/Sgeo/hlist/blob/master/src/lib.rs#L30
17
18/// Used as an index into an `HList`.
19///
20/// `Here` is 0, pointing to the head of the HList.
21///
22/// Users should normally allow type inference to create this type.
23pub struct Here {
24    _priv: (),
25}
26
27/// Used as an index into an `HList`.
28///
29/// `There<T>` is 1 + `T`.
30///
31/// Users should normally allow type inference to create this type.
32pub struct There<T> {
33    _marker: PhantomData<T>,
34}
35
36/// An index denoting that `Suffix` is just that.
37pub struct Suffixed<Suffix> {
38    _marker: PhantomData<Suffix>,
39}
40
41/// Index for the case where we don't need to do any transmogrifying at all because the source
42/// type is the same as the target type.
43pub enum IdentityTransMog {}
44
45/// Index for the case where we need to do work in order to transmogrify one type into another.
46pub struct DoTransmog<PluckByKeyIndex, TransMogIndex> {
47    _marker1: PhantomData<PluckByKeyIndex>,
48    _marker2: PhantomData<TransMogIndex>,
49}
50
51/// Index type wrapper for transmogrifying a generic Source to a generic Target
52pub struct LabelledGenericTransmogIndicesWrapper<T>(PhantomData<T>);
53
54/// Index type wrapper for transmogrifying a generic plucked Source to a generic Target
55pub struct PluckedLabelledGenericIndicesWrapper<T>(T);
56
57/// Index type wrapper for transmogrifying through a (known) container (e.g. `Vec`).
58pub struct MappingIndicesWrapper<T>(PhantomData<T>);