1 | use proc_macro2::Span; |
2 | |
3 | pub trait IntoSpans<S> { |
4 | fn into_spans(self) -> S; |
5 | } |
6 | |
7 | impl IntoSpans<[Span; 1]> for Span { |
8 | fn into_spans(self) -> [Span; 1] { |
9 | [self] |
10 | } |
11 | } |
12 | |
13 | impl IntoSpans<[Span; 2]> for Span { |
14 | fn into_spans(self) -> [Span; 2] { |
15 | [self, self] |
16 | } |
17 | } |
18 | |
19 | impl IntoSpans<[Span; 3]> for Span { |
20 | fn into_spans(self) -> [Span; 3] { |
21 | [self, self, self] |
22 | } |
23 | } |
24 | |
25 | impl IntoSpans<[Span; 1]> for [Span; 1] { |
26 | fn into_spans(self) -> [Span; 1] { |
27 | self |
28 | } |
29 | } |
30 | |
31 | impl IntoSpans<[Span; 2]> for [Span; 2] { |
32 | fn into_spans(self) -> [Span; 2] { |
33 | self |
34 | } |
35 | } |
36 | |
37 | impl IntoSpans<[Span; 3]> for [Span; 3] { |
38 | fn into_spans(self) -> [Span; 3] { |
39 | self |
40 | } |
41 | } |
42 | |
43 | #[cfg (feature = "parsing" )] |
44 | pub trait FromSpans: Sized { |
45 | fn from_spans(spans: &[Span]) -> Self; |
46 | } |
47 | |
48 | #[cfg (feature = "parsing" )] |
49 | impl FromSpans for [Span; 1] { |
50 | fn from_spans(spans: &[Span]) -> Self { |
51 | [spans[0]] |
52 | } |
53 | } |
54 | |
55 | #[cfg (feature = "parsing" )] |
56 | impl FromSpans for [Span; 2] { |
57 | fn from_spans(spans: &[Span]) -> Self { |
58 | [spans[0], spans[1]] |
59 | } |
60 | } |
61 | |
62 | #[cfg (feature = "parsing" )] |
63 | impl FromSpans for [Span; 3] { |
64 | fn from_spans(spans: &[Span]) -> Self { |
65 | [spans[0], spans[1], spans[2]] |
66 | } |
67 | } |
68 | |