haskell_bits/
typeapp.rs

1pub trait TypeAppParam {
2    type Param;
3}
4
5pub trait WithTypeArg<T: ?Sized> {
6    type Type: TypeApp<Self, T>;
7}
8
9pub trait TypeApp<TCon, T>:
10    is_type::Is<Type = <TCon as WithTypeArg<T>>::Type> + TypeAppParam
11where
12    TCon: WithTypeArg<T> + ?Sized,
13    T: ?Sized,
14{
15}
16
17pub struct Ref {}
18pub struct Val {}
19
20// This is useful for traits like CallMap where you're not sure whether your impls are either taking
21// reference or value arguments.
22// There might be a cleaner approach to this but I haven't found it.
23pub trait TypeAppMaybeRef<TCon, T, RefT>
24where
25    TCon: WithTypeArg<T> + ?Sized,
26    T: ?Sized,
27    RefT: ?Sized,
28{
29}
30
31impl<TCon, T, TCollection> TypeAppMaybeRef<TCon, T, Val> for TCollection
32where
33    TCollection: TypeApp<TCon, T>,
34    TCon: WithTypeArg<T> + ?Sized,
35    T: ?Sized,
36{
37}
38
39impl<TCon, T, TCollection> TypeAppMaybeRef<TCon, T, Ref> for &TCollection
40where
41    TCollection: TypeApp<TCon, T>,
42    TCon: WithTypeArg<T> + ?Sized,
43    T: ?Sized,
44{
45}