typestates_comparison/lib.rs
1/*! Comparison of different implementations of typestates.
2
3There are three primary ways of implementing typestates:
4- individual types,
5- generic type with phantom types,
6- generic type with real types.
7
8The last approach can also be implemented with the help of the
9[`typestate`](https://crates.io/crates/typestate) crate.
10
11In this library we compare the three approaches by implementing the following system.
12- An entity gets created with an ID.
13- We can add a key `a` or `b` to the entity, but not both.
14- After we've added `a` or `b`, we can add `c`.
15- The entity is now ready to be used, i.e. printed.
16
17# Examples
18
19## Individual types
20
21```
22use typestates_comparison::individual_types::*;
23let e = Initial::new(42);
24let e = e.add_a(3.14);
25let e = e.add_c('a');
26assert_eq!(e.format(), format!("id:42 a:3.14 c:a"));
27```
28
29## Generic type with phantom types
30
31```
32use typestates_comparison::phantom_types::*;
33let e = Entity::new(42);
34let e = e.add_a(3.14);
35let e = e.add_c('a');
36assert_eq!(e.format(), format!("id:42 a:3.14 c:a"));
37```
38
39## Generic type with real types
40
41```
42use typestates_comparison::real_types::*;
43let e = Entity::new(42);
44let e = e.add_a(3.14);
45let e = e.add_c('a');
46assert_eq!(e.format(), format!("id:42 a:3.14 c:a"));
47```
48
49## Generic type with real types ([`typestate`](https://crates.io/crates/typestate) crate)
50
51```
52use typestates_comparison::typestate_crate::*;
53let e = Entity::new(42);
54let e = e.add_a(3.14);
55let e = e.add_c('a');
56assert_eq!(e.format(), format!("id:42 a:3.14 c:a"));
57```
58
59*/
60
61#![cfg_attr(docsrs, feature(doc_auto_cfg))]
62
63pub mod individual_types;
64pub mod phantom_types;
65pub mod real_types;
66pub mod typestate_crate;