forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
brackets.rs
60 lines (51 loc) · 1.31 KB
/
brackets.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::priv_prelude::*;
macro_rules! define_brackets (
($ty_name:ident) => {
#[derive(Clone, Debug, Serialize)]
pub struct $ty_name<T> {
pub inner: T,
pub span: Span,
}
impl<T> $ty_name<T> {
pub fn new(inner: T, span: Span) -> $ty_name<T> {
$ty_name {
inner,
span,
}
}
pub fn get(&self) -> &T {
&self.inner
}
pub fn into_inner(self) -> T {
self.inner
}
}
impl<T> Spanned for $ty_name<T> {
fn span(&self) -> Span {
self.span.clone()
}
}
};
);
define_brackets!(Braces);
define_brackets!(Parens);
define_brackets!(SquareBrackets);
#[derive(Clone, Debug, Serialize)]
pub struct AngleBrackets<T> {
pub open_angle_bracket_token: OpenAngleBracketToken,
pub inner: T,
pub close_angle_bracket_token: CloseAngleBracketToken,
}
impl<T> AngleBrackets<T> {
pub fn into_inner(self) -> T {
self.inner
}
}
impl<T> Spanned for AngleBrackets<T> {
fn span(&self) -> Span {
Span::join(
self.open_angle_bracket_token.span(),
self.close_angle_bracket_token.span(),
)
}
}