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