Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ pub fn derive_error(input: TokenStream) -> TokenStream {
};

format!(
r#"impl ::{std_crate}::fmt::Display for {name} {{
r"impl ::{std_crate}::fmt::Display for {name} {{
fn fmt(&self, f: &mut ::{std_crate}::fmt::Formatter<'_>) ->
::{std_crate}::result::Result<(), ::{std_crate}::fmt::Error>
{{
{display_matches}
}}
}}"#
}}"
)
};

Expand All @@ -201,25 +201,25 @@ pub fn derive_error(input: TokenStream) -> TokenStream {
let variant_name = v.name;
let from_ty = &v.fields[&index];
let body = if v.ty == VariantType::Tuple {
format!(r#"Self::{variant_name}(value)"#)
format!(r"Self::{variant_name}(value)")
} else {
format!(r#"Self::{variant_name} {{ {index}: value }}"#)
format!(r"Self::{variant_name} {{ {index}: value }}")
};

Some(format!(
r#"impl ::{std_crate}::convert::From<{from_ty}> for {name} {{
r"impl ::{std_crate}::convert::From<{from_ty}> for {name} {{
fn from(value: {from_ty}) -> Self {{
{body}
}}
}}"#
}}"
))
}
_ => None,
})
.collect::<String>();

let code = TokenStream::from_str(&format!(
r#"
r"
impl ::{std_crate}::error::Error for {name} {{
fn source(&self) -> Option<&(dyn ::{std_crate}::error::Error + 'static)> {{
match self {{
Expand All @@ -231,7 +231,7 @@ pub fn derive_error(input: TokenStream) -> TokenStream {

{display_impl}
{from_impls}
"#
"
));

match code {
Expand Down