mirror of https://github.com/zkat/miette.git
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:
parent
26f409c525
commit
385171eb81
|
|
@ -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! {
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue