feat(derive): Allow anything Clone + Into<SourceSpan> to be used as a Span

Fixes: https://github.com/zkat/miette/issues/12
This commit is contained in:
Kat Marchán 2021-08-17 19:29:45 -07:00
parent 26f409c525
commit 385171eb81
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
2 changed files with 8 additions and 6 deletions

View File

@ -200,14 +200,14 @@ impl Snippets {
// Context // Context
let context = &snippet.snippet; let context = &snippet.snippet;
let context = quote! { let context = quote! {
context: self.#context.clone(), context: self.#context.clone().into(),
}; };
// Highlights // Highlights
let highlights = snippet.highlights.iter().map(|highlight| { let highlights = snippet.highlights.iter().map(|highlight| {
let Highlight { highlight } = highlight; let Highlight { highlight } = highlight;
quote! { quote! {
self.#highlight.clone() self.#highlight.clone().into()
} }
}); });
let highlights = quote! { let highlights = quote! {
@ -288,7 +288,7 @@ impl Snippets {
} }
}; };
let context = quote! { let context = quote! {
context: #context.clone(), context: #context.clone().into(),
}; };
// Highlights // Highlights
@ -301,7 +301,7 @@ impl Snippets {
} }
}; };
quote! { quote! {
#m.clone() #m.clone().into()
} }
}); });
let highlights = quote! { let highlights = quote! {

View File

@ -193,9 +193,11 @@ fn test_snippet_named_struct() {
// | | // | |
// | var 1 // | var 1
#[highlight(snip)] #[highlight(snip)]
var1: SourceSpan, // label from SourceSpan is used, if any. // label from SourceSpan is used, if any.
var1: SourceSpan,
#[highlight(snip)] #[highlight(snip)]
var2: SourceSpan, // Anything that's Clone + Into<SourceSpan> can be used here.
var2: (String, usize, usize),
// Now with member source names // Now with member source names
filename: String, filename: String,