Skip to main content

typed_quote/tokens/
concat.rs

1use super::*;
2
3impl<A: IntoTokens, B: IntoTokens> sealed::IntoTokens for Concat<A, B> {}
4impl<A: IntoTokens, B: IntoTokens> IntoTokens for Concat<A, B> {
5    crate::impl_into_tokens!(
6        |self, ts| {
7            () = (self.0, &mut *ts).into_st();
8            () = (self.1, ts).into_st();
9        },
10        {
11            let mut ts = self.0.into_st();
12            () = (self.1, &mut ts).into_st();
13            ts
14        },
15    );
16}
17
18impl<A: IntoTokens, B: IntoTokens, S: crate::Span> sealed::IntoTokens
19    for ConcatWithDefaultSpan<A, B, S>
20{
21}
22impl<A: IntoTokens + WithSpan, B: IntoTokens + WithSpan, S: crate::Span> IntoTokens
23    for ConcatWithDefaultSpan<A, B, S>
24{
25    crate::impl_into_tokens!(
26        #[proxy]
27        |self| {
28            let Self(a, b, span) = self;
29            Concat(a.with_default_span(span), b.with_default_span(span))
30        }
31    );
32}
33
34impl<A: IntoTokens, B: IntoTokens, S: crate::Span> sealed::IntoTokens
35    for ConcatWithReplacedSpan<A, B, S>
36{
37}
38impl<A: IntoTokens + WithSpan, B: IntoTokens + WithSpan, S: crate::Span> IntoTokens
39    for ConcatWithReplacedSpan<A, B, S>
40{
41    crate::impl_into_tokens!(
42        #[proxy]
43        |self| {
44            let Self(a, b, span) = self;
45            Concat(a.with_replaced_span(span), b.with_replaced_span(span))
46        }
47    );
48}
49
50impl<A: ToTokens, B: ToTokens> sealed::ToTokens for Concat<A, B> {}
51impl<A: ToTokens, B: ToTokens> ToTokens for Concat<A, B> {
52    crate::impl_to_tokens!(
53        |self, ts| {
54            () = (&self.0, &mut *ts).into_st();
55            () = (&self.1, ts).into_st();
56        },
57        {
58            let mut ts = (&self.0).into_st();
59            () = (&self.1, &mut ts).into_st();
60            ts
61        },
62    );
63}
64
65impl<A: ToTokens, B: ToTokens, S: crate::Span> sealed::ToTokens for ConcatWithDefaultSpan<A, B, S> {}
66impl<A: ToTokens + RefWithSpan, B: ToTokens + RefWithSpan, S: crate::Span> ToTokens
67    for ConcatWithDefaultSpan<A, B, S>
68{
69    crate::impl_to_tokens!(
70        #[proxy]
71        |self| {
72            let Self(a, b, span) = self;
73            let span = *span;
74            Concat(a.ref_with_default_span(span), b.ref_with_default_span(span))
75        }
76    );
77}
78
79impl<A: ToTokens, B: ToTokens, S: crate::Span> sealed::ToTokens
80    for ConcatWithReplacedSpan<A, B, S>
81{
82}
83impl<A: ToTokens + RefWithSpan, B: ToTokens + RefWithSpan, S: crate::Span> ToTokens
84    for ConcatWithReplacedSpan<A, B, S>
85{
86    crate::impl_to_tokens!(
87        #[proxy]
88        |self| {
89            let Self(a, b, span) = self;
90            let span = *span;
91            Concat(
92                a.ref_with_replaced_span(span),
93                b.ref_with_replaced_span(span),
94            )
95        }
96    );
97}
98
99impl<A: WithSpan, B: WithSpan> sealed::WithSpan for Concat<A, B> {}
100impl<A: WithSpan, B: WithSpan> WithSpan for Concat<A, B> {
101    type WithDefaultSpan<S: crate::Span> = ConcatWithDefaultSpan<A, B, S>;
102
103    fn with_default_span<S: crate::Span>(self, span: S) -> Self::WithDefaultSpan<S> {
104        ConcatWithDefaultSpan(self.0, self.1, span)
105    }
106
107    type WithReplacedSpan<S: crate::Span> = ConcatWithReplacedSpan<A, B, S>;
108
109    fn with_replaced_span<S: crate::Span>(self, span: S) -> Self::WithReplacedSpan<S> {
110        ConcatWithReplacedSpan(self.0, self.1, span)
111    }
112}
113
114impl<A: WithSpan, B: WithSpan, SO: crate::Span> sealed::WithSpan
115    for ConcatWithDefaultSpan<A, B, SO>
116{
117}
118impl<A: WithSpan, B: WithSpan, SO: crate::Span> WithSpan for ConcatWithDefaultSpan<A, B, SO> {
119    type WithDefaultSpan<S: crate::Span> = Self;
120
121    fn with_default_span<S: crate::Span>(self, _: S) -> Self::WithDefaultSpan<S> {
122        self
123    }
124
125    type WithReplacedSpan<S: crate::Span> = ConcatWithReplacedSpan<A, B, S>;
126
127    fn with_replaced_span<S: crate::Span>(self, span: S) -> Self::WithReplacedSpan<S> {
128        let Self(a, b, _) = self;
129        ConcatWithReplacedSpan(a, b, span)
130    }
131}
132
133impl<A: WithSpan, B: WithSpan, SO: crate::Span> sealed::WithSpan
134    for ConcatWithReplacedSpan<A, B, SO>
135{
136}
137impl<A: WithSpan, B: WithSpan, SO: crate::Span> WithSpan for ConcatWithReplacedSpan<A, B, SO> {
138    type WithDefaultSpan<S: crate::Span> = Self;
139
140    fn with_default_span<S: crate::Span>(self, _: S) -> Self::WithDefaultSpan<S> {
141        self
142    }
143
144    type WithReplacedSpan<S: crate::Span> = ConcatWithReplacedSpan<A, B, S>;
145
146    fn with_replaced_span<S: crate::Span>(self, span: S) -> Self::WithReplacedSpan<S> {
147        let Self(a, b, _) = self;
148        ConcatWithReplacedSpan(a, b, span)
149    }
150}
151
152impl<A: RefWithSpan, B: RefWithSpan> sealed::RefWithSpan for Concat<A, B> {}
153impl<A: RefWithSpan, B: RefWithSpan> RefWithSpan for Concat<A, B> {
154    type RefWithDefaultSpan<'a, S: crate::Span>
155        = ConcatWithDefaultSpan<&'a A, &'a B, S>
156    where
157        Self: 'a;
158
159    fn ref_with_default_span<S: crate::Span>(&self, span: S) -> Self::RefWithDefaultSpan<'_, S> {
160        let Self(a, b) = self;
161        ConcatWithDefaultSpan(a, b, span)
162    }
163
164    type RefWithReplacedSpan<'a, S: crate::Span>
165        = ConcatWithReplacedSpan<&'a A, &'a B, S>
166    where
167        Self: 'a;
168
169    fn ref_with_replaced_span<S: crate::Span>(&self, span: S) -> Self::RefWithReplacedSpan<'_, S> {
170        let Self(a, b) = self;
171        ConcatWithReplacedSpan(a, b, span)
172    }
173}
174
175impl<A: RefWithSpan, B: RefWithSpan, S: crate::Span> sealed::RefWithSpan
176    for ConcatWithDefaultSpan<A, B, S>
177{
178}
179impl<A: RefWithSpan, B: RefWithSpan, SO: crate::Span> RefWithSpan
180    for ConcatWithDefaultSpan<A, B, SO>
181{
182    type RefWithDefaultSpan<'a, S: crate::Span>
183        = &'a Self
184    where
185        Self: 'a;
186
187    fn ref_with_default_span<S: crate::Span>(&self, _: S) -> Self::RefWithDefaultSpan<'_, S> {
188        self
189    }
190
191    type RefWithReplacedSpan<'a, S: crate::Span>
192        = ConcatWithReplacedSpan<&'a A, &'a B, S>
193    where
194        Self: 'a;
195
196    fn ref_with_replaced_span<S: crate::Span>(&self, span: S) -> Self::RefWithReplacedSpan<'_, S> {
197        let Self(a, b, _) = self;
198        ConcatWithReplacedSpan(a, b, span)
199    }
200}
201
202impl<A: RefWithSpan, B: RefWithSpan, S: crate::Span> sealed::RefWithSpan
203    for ConcatWithReplacedSpan<A, B, S>
204{
205}
206impl<A: RefWithSpan, B: RefWithSpan, SO: crate::Span> RefWithSpan
207    for ConcatWithReplacedSpan<A, B, SO>
208{
209    type RefWithDefaultSpan<'a, S: crate::Span>
210        = &'a Self
211    where
212        Self: 'a;
213
214    fn ref_with_default_span<S: crate::Span>(&self, _: S) -> Self::RefWithDefaultSpan<'_, S> {
215        self
216    }
217
218    type RefWithReplacedSpan<'a, S: crate::Span>
219        = ConcatWithReplacedSpan<&'a A, &'a B, S>
220    where
221        Self: 'a;
222
223    fn ref_with_replaced_span<S: crate::Span>(&self, span: S) -> Self::RefWithReplacedSpan<'_, S> {
224        let Self(a, b, _) = self;
225        ConcatWithReplacedSpan(a, b, span)
226    }
227}