Skip to content

feat: Add Debug derives to Slot, SlotGuard, and AppendAndCloseOnDrop#194

Merged
rcoh merged 2 commits into
mainfrom
debug-impls
Feb 1, 2026
Merged

feat: Add Debug derives to Slot, SlotGuard, and AppendAndCloseOnDrop#194
rcoh merged 2 commits into
mainfrom
debug-impls

Conversation

@rcoh
Copy link
Copy Markdown
Contributor

@rcoh rcoh commented Jan 30, 2026

📬 Issue #, if available: Fixes #190

✍️ Description of changes: Add derive(Debug) to Slot & friends. This also required updating the proc macro to pass through Debug when present.

🔏 By submitting this pull request

  • I confirm that I've made a best effort attempt to update all relevant documentation.
  • I confirm that my contribution is made under the terms of the Apache 2.0 license.

@rcoh rcoh requested a review from jlizen January 30, 2026 19:10
Copy link
Copy Markdown
Contributor

@jlizen jlizen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an improvement for sure, but I'm wondering if it could be written in a way that has a lossier debug impl in case T/T::Closed: !Debug. That shows whether things are open or closed.

Comment thread metrique/src/slot.rs Outdated

impl<T: Debug + CloseValue> Debug for SlotGuard<T>
where
T::Closed: Debug,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but is there a reason we wouldn't want to have a custom debug impl for SlotI instead of just the #[derive(Debug)]?

That way (I think) we could have one that is T: Debug and includes the inner contents, or T: !Debug which just shows whether it is still open or not

Comment thread metrique/src/slot.rs Outdated
/// metrics.field_1 += 1;
/// }
/// ```
#[derive(Debug)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same feedback as with SlotI... this is an improvement, but it seems like we could provide a debug impl even if T: !Debug and T::Closed: !Debug?

Comment thread metrique-macro/src/enums.rs Outdated
})
}

fn extract_allowed_derives(attrs: &[Attribute]) -> Ts2 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snapshot test with this would be nice.

Comment thread metrique-macro/src/enums.rs Outdated
let tokens = meta_list.tokens.to_string();
for derive in &allowed {
if tokens.contains(derive) {
found.push(syn::Ident::new(derive, meta_list.span()));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only difference between this one and struct is that we point errors to the derive tokens instead of the metrics macro call site. This seems better / any reason we can't just use the same function for both?

Comment thread metrique/src/keep_alive.rs Outdated

impl Debug for Guard {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Guard").finish()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to show whether guard is open or not

Comment thread metrique/src/lib.rs
}
}

#[derive(Debug)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same feedback

Comment thread metrique/src/lib.rs Outdated
/// // When `metrics` is dropped, it will be closed and appended to the sink
/// # }
/// ```
#[derive(Debug)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same feedback

@rcoh rcoh force-pushed the debug-impls branch 3 times, most recently from 2b5f21d to 6ca7427 Compare February 1, 2026 19:52
@rcoh
Copy link
Copy Markdown
Contributor Author

rcoh commented Feb 1, 2026

I did not opt for a opaque impl — you can't have both due to a lack of specialization and I think most users are fine with #[derive(Debug)] on their structs.

- Unify extract_allowed_derives function between enums and structs
- Add UI test for Debug derives passthrough
- Show open/closed state in Guard Debug impl
@rcoh rcoh merged commit 8626cef into main Feb 1, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

implement Debug for Slot

2 participants