Allow passing any IntoContext to push_extra

This commit is contained in:
Michael Pfaff 2023-07-02 14:31:43 -04:00
parent 71385c9e19
commit c20ceb332a
Signed by: michael
GPG Key ID: CF402C4A012AA9D4
1 changed files with 8 additions and 8 deletions

View File

@ -37,8 +37,13 @@ impl Context {
&mut self.extra
}
pub fn push_extra(&mut self, detail: Detail) {
self.extra.push(detail);
pub fn push_extra(&mut self, detail: impl IntoContext) {
let detail = detail.into_context();
if detail.extra.is_empty() {
self.extra.push(detail.detail);
} else {
self.extra.push(Detail::Context(detail.into()));
}
}
pub fn pop_extra(&mut self) -> Option<Detail> {
@ -177,12 +182,7 @@ impl IntoContext for Context {
#[track_caller]
#[inline]
fn with(mut self, other: impl IntoContext) -> Self {
let other = other.into_context();
if other.extra.is_empty() {
self.extra.push(other.detail);
} else {
self.extra.push(Detail::Context(other.into()));
}
self.push_extra(other);
self
}
}