Debian Codegraph @

src/build/state.rs

raw symbols SCIP
1 //! Builder typestates.
2
3 /// Start of URI/IRI reference.
4 pub struct Start(());
5 /// Start of URI/IRI.
6 pub struct NonRefStart(());
7 /// End of scheme.
8 pub struct SchemeEnd(());
9 /// Start of authority.
10 pub struct AuthorityStart(());
11 /// End of userinfo.
12 pub struct UserinfoEnd(());
13 /// End of host.
14 pub struct HostEnd(());
15 /// End of port.
16 pub struct PortEnd(());
17 /// End of authority.
18 pub struct AuthorityEnd(());
19 /// End of path.
20 pub struct PathEnd(());
21 /// End of query.
22 pub struct QueryEnd(());
23 /// End of fragment
24 pub struct FragmentEnd(());
25 /// End of URI/IRI (reference).
26 pub struct End(());
27
28 /// Indicates the next possible state.
29 pub trait To<T> {}
30 /// Indicates the next possible state to advance to.
31 pub trait AdvanceTo<T>: To<T> {}
32
33 macro_rules! impl_many {
34 ($trait:ident for $($x:ty => $($y:ty),+)*) => {
35 $($(
36 impl $trait<$y> for $x {}
37 )+)*
38 };
39 }
40
41 impl_many! { To for
42 Start => SchemeEnd, AuthorityStart, PathEnd
43 NonRefStart => SchemeEnd
44 SchemeEnd => AuthorityStart, PathEnd
45 AuthorityStart => UserinfoEnd, HostEnd
46 UserinfoEnd => HostEnd
47 HostEnd => PortEnd, AuthorityEnd
48 PortEnd => AuthorityEnd
49 AuthorityEnd => PathEnd
50 PathEnd => QueryEnd, FragmentEnd, End
51 QueryEnd => FragmentEnd, End
52 FragmentEnd => End
53 }
54
55 impl<S: To<AuthorityStart>> To<AuthorityEnd> for S {}
56
57 impl_many! { AdvanceTo for
58 Start => SchemeEnd, AuthorityEnd
59 SchemeEnd => AuthorityEnd
60 AuthorityStart => UserinfoEnd
61 HostEnd => PortEnd
62 PathEnd => QueryEnd, FragmentEnd
63 QueryEnd => FragmentEnd
64 }