1 pub type Result
<T
> = std
::result
::Result
<T
, Error
>;
3 #[derive(Default, Debug)]
7 span
: Option
<(usize, usize)>,
10 impl std
::error
::Error
for Error {}
12 impl From
<Error
> for std
::io
::Error
{
13 fn from(error
: Error
) -> Self {
14 std
::io
::Error
::new(std
::io
::ErrorKind
::Other
, error
.message
.as_str())
18 impl From
<syn
::Error
> for Error
{
19 fn from(error
: syn
::Error
) -> Self {
20 let start
= error
.span().start();
21 Self { message: error.to_string(), span: Some((start.line, start.column)), ..Self::default() }
25 impl std
::fmt
::Display
for Error
{
26 fn fmt(&self, fmt
: &mut std
::fmt
::Formatter
<'_
>) -> std
::fmt
::Result
{
27 writeln
!(fmt
, "error: {}", self.message
)?
;
28 if !self.path
.is_empty() {
29 if let Some((line
, column
)) = self.span
{
30 writeln
!(fmt
, " --> {}:{line}:{column}", self.path
)?
;
32 writeln
!(fmt
, " --> {}", self.path
)?
;
40 pub(crate) fn new(message
: &str) -> Self {
41 Self { message: message.to_string(), ..Self::default() }
44 pub(crate) fn with_path(self, path
: &str) -> Self {
45 Self { path: path.to_string(), ..self }