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
use crate::Span;
#[derive(Debug, Clone)]
pub struct Source {
pub name: String,
pub source: String,
}
impl Source {
pub fn new<N, S>(name: N, source: S) -> Self
where
N: AsRef<str>,
S: AsRef<str>,
{
Self {
name: name.as_ref().to_owned(),
source: source.as_ref().to_owned(),
}
}
}
impl Source {
pub fn source(&self, span: Span) -> Option<&'_ str> {
self.source.get(span.start..span.end)
}
pub fn end(&self) -> usize {
self.source.len()
}
pub fn as_str(&self) -> &str {
&self.source
}
}