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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use source_span::Span;
use std::fmt;
use std::ops::Deref;
pub struct Located<T> {
t: T,
span: Span
}
impl<T> Located<T> {
pub fn new(t: T, span: Span) -> Located<T> {
Located {
t: t,
span: span
}
}
pub fn into_inner(self) -> T {
self.t
}
pub fn span(&self) -> Span {
self.span
}
}
impl<T> Deref for Located<T> {
type Target = T;
fn deref(&self) -> &T {
&self.t
}
}
impl<T: PartialEq> PartialEq for Located<T> {
fn eq(&self, other: &Located<T>) -> bool {
self.span == other.span && self.t == other.t
}
}
impl<T: Eq> Eq for Located<T> {}
impl<T: fmt::Display> fmt::Display for Located<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.t.fmt(f)
}
}
impl<T: fmt::Debug> fmt::Debug for Located<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.t.fmt(f)
}
}
impl<T: Clone> Clone for Located<T> {
fn clone(&self) -> Self {
Located {
t: self.t.clone(),
span: self.span
}
}
}
impl<T> AsRef<T> for Located<T> {
fn as_ref(&self) -> &T {
&self.t
}
}
impl<T> AsMut<T> for Located<T> {
fn as_mut(&mut self) -> &mut T {
&mut self.t
}
}