Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/rust/syn/span.rs
38271 views
1
// SPDX-License-Identifier: Apache-2.0 OR MIT
2
3
use proc_macro2::extra::DelimSpan;
4
use proc_macro2::{Delimiter, Group, Span, TokenStream};
5
6
#[doc(hidden)]
7
pub trait IntoSpans<S> {
8
fn into_spans(self) -> S;
9
}
10
11
impl IntoSpans<Span> for Span {
12
fn into_spans(self) -> Span {
13
self
14
}
15
}
16
17
impl IntoSpans<[Span; 1]> for Span {
18
fn into_spans(self) -> [Span; 1] {
19
[self]
20
}
21
}
22
23
impl IntoSpans<[Span; 2]> for Span {
24
fn into_spans(self) -> [Span; 2] {
25
[self, self]
26
}
27
}
28
29
impl IntoSpans<[Span; 3]> for Span {
30
fn into_spans(self) -> [Span; 3] {
31
[self, self, self]
32
}
33
}
34
35
impl IntoSpans<[Span; 1]> for [Span; 1] {
36
fn into_spans(self) -> [Span; 1] {
37
self
38
}
39
}
40
41
impl IntoSpans<[Span; 2]> for [Span; 2] {
42
fn into_spans(self) -> [Span; 2] {
43
self
44
}
45
}
46
47
impl IntoSpans<[Span; 3]> for [Span; 3] {
48
fn into_spans(self) -> [Span; 3] {
49
self
50
}
51
}
52
53
impl IntoSpans<DelimSpan> for Span {
54
fn into_spans(self) -> DelimSpan {
55
let mut group = Group::new(Delimiter::None, TokenStream::new());
56
group.set_span(self);
57
group.delim_span()
58
}
59
}
60
61
impl IntoSpans<DelimSpan> for DelimSpan {
62
fn into_spans(self) -> DelimSpan {
63
self
64
}
65
}
66
67