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
use std::fmt;
use std::path::Path;
pub use file::File;
pub use parser::{Event, Parser};
pub use tag::Tag;
mod file;
mod parser;
mod reader;
pub mod path;
pub mod tag;
pub struct Error {
pub line: usize,
pub column: usize,
pub message: String,
}
pub type Result<T> = std::result::Result<T, Error>;
impl fmt::Debug for Error {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
if self.line > 0 && self.column > 0 {
write!(formatter, "{} (line {}, column {})", self.message, self.line, self.column)
} else if self.line > 0 {
write!(formatter, "{} (line {})", self.message, self.line)
} else {
fmt::Debug::fmt(&self.message, formatter)
}
}
}
#[inline]
pub fn open<T: AsRef<Path>>(path: T) -> Result<File> {
File::open(path)
}
#[cfg(test)]
mod tests {
use std::fs;
use std::path::PathBuf;
pub fn find_fixture(name: &str) -> PathBuf {
let mut path = PathBuf::from("tests").join("fixtures").join(name);
path.set_extension("svg");
assert!(fs::metadata(&path).is_ok());
path
}
}