Debian Codegraph @

src/image/recursive.rs

raw symbols SCIP
1 //! A generic wrapper which can be used to represent recursive types.
2 //! Supports conversion from and to tuples of the same size.
3
4 /// No more recursion. Can be used within any `Recursive<NoneMore, YourValue>` type.
5 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
6 pub struct NoneMorerust-analyzer cargo exr 1.74.0 image/recursive/NoneMore#;
7
8 /// A recursive type-level linked list of `Value` entries.
9 /// Mainly used to represent an arbitrary number of channels.
10 /// The recursive architecture removes the need to implement traits for many different tuples.
11 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
12 pub struct Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#<Inner, Value> {
13 /// The remaining values of this linked list,
14 /// probably either `NoneMore` or another instance of the same `Recursive<Inner - 1, Value>`.
15 pub innerrust-analyzer cargo exr 1.74.0 image/recursive/Recursive#inner.: Inner,
16
17 /// The next item in this linked list.
18 pub valuerust-analyzer cargo exr 1.74.0 image/recursive/Recursive#value.: Value,
19 }
20
21 impl<Inner, Value> Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#<Inner, Value> {
22 /// Create a new recursive type. Equivalent to the manual constructor, but less verbose.
23 pub fn newrust-analyzer cargo exr 1.74.0 image/recursive/impl#[`Recursive<Inner, Value>`]new().(inner: Inner, value: Value) -> Selfrust-analyzer cargo exr 1.74.0 image/recursive/impl#[`Recursive<Inner, Value>`] { Selfrust-analyzer cargo exr 1.74.0 image/recursive/impl#[`Recursive<Inner, Value>`] { innerrust-analyzer cargo exr 1.74.0 image/recursive/Recursive#inner., valuerust-analyzer cargo exr 1.74.0 image/recursive/Recursive#value. } }
24 }
25
26 /// Convert this recursive type into a tuple.
27 /// This is nice as it will require less typing for the same type.
28 /// A type might or might not be convertible to the specified `Tuple` type.
29 pub trait IntoTuplerust-analyzer cargo exr 1.74.0 image/recursive/IntoTuple#<Tuple> {
30 /// Convert this recursive type to a nice tuple.
31 fn into_tuplerust-analyzer cargo exr 1.74.0 image/recursive/IntoTuple#into_tuple().(self) -> Tuple;
32 }
33
34 /// Convert this recursive type into a tuple.
35 /// This is nice as it will require less typing for the same type.
36 /// A type will be converted to the specified `Self::NonRecursive` type.
37 pub trait IntoNonRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoNonRecursive# {
38 /// The resulting tuple type.
39 type NonRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoNonRecursive#NonRecursive#;
40
41 /// Convert this recursive type to a nice tuple.
42 fn into_non_recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoNonRecursive#into_non_recursive().(self) -> Self::NonRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoNonRecursive#NonRecursive#;
43 }
44
45 /// Create a recursive type from this tuple.
46 pub trait IntoRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive# {
47 /// The recursive type resulting from this tuple.
48 type Recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#Recursive#;
49
50 /// Create a recursive type from this tuple.
51 fn into_recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#into_recursive().(self) -> Self::Recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#Recursive#;
52 }
53
54 impl IntoRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive# for NoneMorerust-analyzer cargo exr 1.74.0 image/recursive/NoneMore# {
55 type Recursiverust-analyzer cargo exr 1.74.0 image/recursive/impl#[NoneMore][IntoRecursive]Recursive# = Selfrust-analyzer cargo exr 1.74.0 image/recursive/impl#[NoneMore][IntoRecursive];
56 fn into_recursiverust-analyzer cargo exr 1.74.0 image/recursive/impl#[NoneMore][IntoRecursive]into_recursive().(self) -> Selfrust-analyzer cargo exr 1.74.0 image/recursive/impl#[NoneMore][IntoRecursive]::Recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#Recursive# { self }
57 }
58
59 impl<Inner: IntoRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#, Value> IntoRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive# for Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#<Inner, Value> {
60 type Recursiverust-analyzer cargo exr 1.74.0 image/recursive/impl#[`Recursive<Inner, Value>`][IntoRecursive]Recursive# = Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#<Inner::Recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#Recursive#, Value>;
61 fn into_recursiverust-analyzer cargo exr 1.74.0 image/recursive/impl#[`Recursive<Inner, Value>`][IntoRecursive]into_recursive().(self) -> Selfrust-analyzer cargo exr 1.74.0 image/recursive/impl#[`Recursive<Inner, Value>`][IntoRecursive]::Recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#Recursive# { Recursiverust-analyzer cargo exr 1.74.0 image/recursive/Recursive#::newrust-analyzer cargo exr 1.74.0 image/recursive/impl#[`Recursive<Inner, Value>`]new().(self.innerrust-analyzer cargo exr 1.74.0 image/recursive/Recursive#inner..into_recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#into_recursive().(), self.valuerust-analyzer cargo exr 1.74.0 image/recursive/Recursive#value.) }
62 }
63
64 // Automatically implement IntoTuple so we have to generate less code in the macros
65 impl<I: IntoNonRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoNonRecursive#> IntoTuplerust-analyzer cargo exr 1.74.0 image/recursive/IntoTuple#<I::NonRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoNonRecursive#NonRecursive#> for I {
66 fn into_tuplerust-analyzer cargo exr 1.74.0 image/recursive/impl#[I][`IntoTuple<<I as IntoNonRecursive>::NonRecursive>`]into_tuple().(self) -> <I as IntoNonRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoNonRecursive#>::NonRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoNonRecursive#NonRecursive# {
67 self.into_non_recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoNonRecursive#into_non_recursive().()
68 }
69 }
70
71 //Implement traits for the empty tuple, the macro doesn't handle that
72 impl IntoRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive# for () {
73 type Recursiverust-analyzer cargo exr 1.74.0 image/recursive/impl#[`()`][IntoRecursive]Recursive# = NoneMorerust-analyzer cargo exr 1.74.0 image/recursive/NoneMore#;
74 fn into_recursiverust-analyzer cargo exr 1.74.0 image/recursive/impl#[`()`][IntoRecursive]into_recursive().(self) -> Selfrust-analyzer cargo exr 1.74.0 image/recursive/impl#[`()`][IntoRecursive]::Recursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoRecursive#Recursive# { NoneMorerust-analyzer cargo exr 1.74.0 image/recursive/NoneMore# }
75 }
76
77 impl IntoNonRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoNonRecursive# for NoneMorerust-analyzer cargo exr 1.74.0 image/recursive/NoneMore# {
78 type NonRecursiverust-analyzer cargo exr 1.74.0 image/recursive/impl#[NoneMore][IntoNonRecursive]NonRecursive# = ();
79
80 fn into_non_recursiverust-analyzer cargo exr 1.74.0 image/recursive/impl#[NoneMore][IntoNonRecursive]into_non_recursive().(self) -> Selfrust-analyzer cargo exr 1.74.0 image/recursive/impl#[NoneMore][IntoNonRecursive]::NonRecursiverust-analyzer cargo exr 1.74.0 image/recursive/IntoNonRecursive#NonRecursive# {
81 ()
82 }
83 }
84
85 /// Generates the recursive type corresponding to this tuple:
86 /// ```nocheck
87 /// gen_recursive_type!(A, B, C)
88 /// => Recursive<Recursive<Recursive<NoneMore, A>, B>, C>
89 /// ```
90 macro_rules! gen_recursive_typerust-analyzer cargo exr 1.74.0 image/recursive/gen_recursive_type! {
91 () => { NoneMore };
92 ($last:ident $(,$not_last:ident)*) => {
93 Recursive<gen_recursive_type!($($not_last),*), $last>
94 };
95 }
96
97 /// Generates the recursive value corresponding to the given indices:
98 /// ```nocheck
99 /// gen_recursive_value(self; 1, 0)
100 /// => Recursive { inner: Recursive { inner: NoneMore, value: self.0 }, value: self.1 }
101 /// ```
102 macro_rules! gen_recursive_valuerust-analyzer cargo exr 1.74.0 image/recursive/gen_recursive_value! {
103 ($self:ident;) => { NoneMore };
104 ($self:ident; $last:tt $(,$not_last:tt)*) => {
105 Recursive { inner: gen_recursive_value!($self; $($not_last),*), value: $self.$last }
106 };
107 }
108
109 /// Generates the into_tuple value corresponding to the given type names:
110 /// ```nocheck
111 /// gen_tuple_value(self; A, B, C)
112 /// => (self.inner.inner.value, self.inner.value, self.value)
113 /// ```
114 macro_rules! gen_tuple_valuerust-analyzer cargo exr 1.74.0 image/recursive/gen_tuple_value! {
115 ($self:ident; $($all:ident),* ) => {
116 gen_tuple_value!(@ $self; (); $($all),* )
117 };
118
119 (@ $self:ident; ($($state:expr),*);) => { ($($state .value,)*) };
120 (@ $self:ident; ($($state:expr),*); $last:ident $(,$not_last:ident)* ) => {
121 gen_tuple_value!(@ $self; ($($state .inner,)* $self); $($not_last),* )
122 };
123 }
124
125 /// Generate the trait implementations given a sequence of type names in both directions and the indices backwards:
126 /// ```nocheck
127 /// generate_single(A, B, C; C, B, A; 2, 1, 0)
128 /// ```
129 macro_rules! generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single! {
130 ( $($name_fwd:ident),* ; $($name_back:ident),* ; $($index_back:tt),*) => {
131 impl<$($name_fwd),*> IntoNonRecursive for gen_recursive_type!($($name_back),*) {
132 type NonRecursive = ($($name_fwd,)*);
133 fn into_non_recursive(self) -> Self::NonRecursive {
134 gen_tuple_value!(self; $($name_fwd),*)
135 }
136 }
137
138 impl<$($name_fwd),*> IntoRecursive for ($($name_fwd,)*) {
139 type Recursive = gen_recursive_type!($($name_back),*);
140 fn into_recursive(self) -> Self::Recursive {
141 gen_recursive_value!(self; $($index_back),*)
142 }
143 }
144 };
145 }
146
147 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A; A; 0);
148 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B; B,A; 1,0);
149 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C; C,B,A; 2,1,0);
150 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D; D,C,B,A; 3,2,1,0);
151 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E; E,D,C,B,A; 4,3,2,1,0);
152 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F; F,E,D,C,B,A; 5,4,3,2,1,0);
153 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G; G,F,E,D,C,B,A; 6,5,4,3,2,1,0);
154 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H; H,G,F,E,D,C,B,A; 7,6,5,4,3,2,1,0);
155 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I; I,H,G,F,E,D,C,B,A; 8,7,6,5,4,3,2,1,0);
156 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J; J,I,H,G,F,E,D,C,B,A; 9,8,7,6,5,4,3,2,1,0);
157 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K; K,J,I,H,G,F,E,D,C,B,A; 10,9,8,7,6,5,4,3,2,1,0);
158 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L; L,K,J,I,H,G,F,E,D,C,B,A; 11,10,9,8,7,6,5,4,3,2,1,0);
159 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M; M,L,K,J,I,H,G,F,E,D,C,B,A; 12,11,10,9,8,7,6,5,4,3,2,1,0);
160 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N; N,M,L,K,J,I,H,G,F,E,D,C,B,A; 13,12,11,10,9,8,7,6,5,4,3,2,1,0);
161 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O; O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
162 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P; P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
163 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q; Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
164 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R; R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
165 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S; S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
166 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T; T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
167 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U; U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
168 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V; V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
169 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W; W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
170 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X; X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
171 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y; Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
172 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z; Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
173 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,A1; A1,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
174 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,A1,B1; B1,A1,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
175 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,A1,B1,C1; C1,B1,A1,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
176 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,A1,B1,C1,D1; D1,C1,B1,A1,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
177 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,A1,B1,C1,D1,E1; E1,D1,C1,B1,A1,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
178 generate_singlerust-analyzer cargo exr 1.74.0 image/recursive/generate_single!!(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,A1,B1,C1,D1,E1,F1; F1,E1,D1,C1,B1,A1,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A; 31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);