mirror of https://github.com/zkat/miette.git
feat(collection): remove unnecessary `OptionalWrapper`
- In a label collection, there is no need for a `None` label. One should just not add that label - Code wise it is also incorrect. The wrapper will be for a vector of spans, not for individual spans. It happens to work anyway, but this was not the intended use.
This commit is contained in:
parent
85576d7914
commit
589eacc2c3
|
|
@ -197,7 +197,7 @@ impl Labels {
|
||||||
let Label {
|
let Label {
|
||||||
span,
|
span,
|
||||||
label,
|
label,
|
||||||
ty,
|
ty: _,
|
||||||
lbl_ty,
|
lbl_ty,
|
||||||
} = label;
|
} = label;
|
||||||
if *lbl_ty != LabelType::Collection {
|
if *lbl_ty != LabelType::Collection {
|
||||||
|
|
@ -212,16 +212,13 @@ impl Labels {
|
||||||
Some(quote! {
|
Some(quote! {
|
||||||
.chain({
|
.chain({
|
||||||
let display = #display;
|
let display = #display;
|
||||||
self.#span.iter().map(move |label| {
|
self.#span.iter().map(move |span| {
|
||||||
miette::macro_helpers::OptionalWrapper::<#ty>::new().to_option(label)
|
use miette::macro_helpers::{ToLabelSpanWrapper,ToLabeledSpan};
|
||||||
.map(|span| {
|
let mut labeled_span = ToLabelSpanWrapper::to_labeled_span(span.clone());
|
||||||
use miette::macro_helpers::{ToLabelSpanWrapper,ToLabeledSpan};
|
if display.is_some() && labeled_span.label().is_none() {
|
||||||
let mut labeled_span = ToLabelSpanWrapper::to_labeled_span(span.clone());
|
labeled_span.set_label(display.clone())
|
||||||
if display.is_some() && labeled_span.label().is_none() {
|
}
|
||||||
labeled_span.set_label(display.clone())
|
Some(labeled_span)
|
||||||
}
|
|
||||||
labeled_span
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -284,7 +281,7 @@ impl Labels {
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
let collections_chain = labels.0.iter().filter_map(|label| {
|
let collections_chain = labels.0.iter().filter_map(|label| {
|
||||||
let Label { span, label, ty, lbl_ty } = label;
|
let Label { span, label, ty: _, lbl_ty } = label;
|
||||||
if *lbl_ty != LabelType::Collection {
|
if *lbl_ty != LabelType::Collection {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
@ -303,16 +300,13 @@ impl Labels {
|
||||||
Some(quote! {
|
Some(quote! {
|
||||||
.chain({
|
.chain({
|
||||||
let display = #display;
|
let display = #display;
|
||||||
#field.iter().map(move |label| {
|
#field.iter().map(move |span| {
|
||||||
miette::macro_helpers::OptionalWrapper::<#ty>::new().to_option(label)
|
use miette::macro_helpers::{ToLabelSpanWrapper,ToLabeledSpan};
|
||||||
.map(|span| {
|
let mut labeled_span = ToLabelSpanWrapper::to_labeled_span(span.clone());
|
||||||
use miette::macro_helpers::{ToLabelSpanWrapper,ToLabeledSpan};
|
if display.is_some() && labeled_span.label().is_none() {
|
||||||
let mut labeled_span = ToLabelSpanWrapper::to_labeled_span(span.clone());
|
labeled_span.set_label(display.clone());
|
||||||
if display.is_some() && labeled_span.label().is_none() {
|
}
|
||||||
labeled_span.set_label(display.clone());
|
Some(labeled_span)
|
||||||
}
|
|
||||||
labeled_span
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue