1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Read the README - it's in the name.
pub use ;
/// Type used as semantic tags.
///
/// Technically, any type can be used as a tag, but the
/// most idiomatic way is to define an empty enum:
/// ```rust
/// pub enum SurnameTag {}
/// impl taggables::SemanticTag for SurnameTag {
/// fn name() -> &'static str {
/// "Surname"
/// }
/// }
/// ```
///
/// For 99% of cases you should not implement this trait manually
/// and use the [semantic_tags] macro instead.
///
/// Implementations are also provided for `()` and [Infallible].
/// While these types carry no information, they naturally map
/// onto important elements in type lattices and categories,
/// which makes them useful for modelling.
///
/// Additionally, by this crate's convention `()` is used as the
/// default "no semantic" tag of types generated by [taggables].
///
/// [Infallible]: core::convert::Infallible
/// Type that carries a semantic tag parameter.
///
/// # Usage
///
/// ```rust
/// # use std::marker::PhantomData;
///
/// pub struct TaggableString<S = ()>(String, PhantomData<fn(S) -> S>);
///
/// impl<S> taggables::Taggable for TaggableString<S> {
/// type Tag = S;
/// type This<T> = TaggableString<T>;
/// fn retag<T>(self) -> TaggableString<T> {
/// TaggableString(self.0, PhantomData)
/// }
/// }
///
/// taggables::semantic_tags! {
/// pub FirstNameTag,
/// pub SurnameTag,
/// }
///
/// pub type FirstName = TaggableString<FirstNameTag>;
/// pub type Surname = TaggableString<SurnameTag>;
/// ```