Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blanket implementations of Recorder for some pointer-like types #512

Merged
merged 6 commits into from
Sep 21, 2024

Conversation

tobz
Copy link
Member

@tobz tobz commented Sep 5, 2024

(I messed up the remote branch in #507 and it was just easier to fix it by making a new branch and PR.)

Rc, Arc, and Box.

Closes #506.

@tobz tobz added C-core Component: core functionality such as traits, etc. E-simple Effort: simple. T-ergonomics Type: ergonomics. labels Sep 5, 2024
@Nekrolm
Copy link
Contributor

Nekrolm commented Sep 6, 2024

Thanks for implementing this!

Can you also add + ?Sized bound for blanket impl to support Box<dyn Recorder> and similar?

Also I can suggest to use macro to not repeat boilerplate
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021

macro_rules! impl_recorder {
    (<$t:tt> for $ptr:ty) => {
        impl <$t> Recorder for $ptr
        where $t : Recorder + ?Sized 
        {
            fn describe_counter(&self, key: &str) {
                $t::describe_counter(self, key)
            }
        }
    }
}

impl_recorder!(<T> for &T);
impl_recorder!(<T> for &mut T);
impl_recorder!(<T> for Box<T>);
impl_recorder!(<T> for std::sync::Arc<T>);
impl_recorder!(<T> for std::rc::Rc<T>);

@tobz
Copy link
Member Author

tobz commented Sep 21, 2024

Yeah, that's a good idea about reducing the boilerplate with a macro, and also adding blanket implementations for borrowed variants.

It also reminded me that we can't have a blanket implementation for Rc<T> now since Recorder has to be Sync.

@tobz tobz force-pushed the david-perez-recorder-pointer-deref-impls branch from 813d8fd to d75265a Compare September 21, 2024 16:25
@tobz tobz merged commit 6e1e7f9 into main Sep 21, 2024
13 checks passed
@tobz tobz deleted the david-perez-recorder-pointer-deref-impls branch September 21, 2024 17:46
@tobz tobz added the S-awaiting-release Status: awaiting a release to be considered fixed/implemented. label Sep 21, 2024
@tobz
Copy link
Member Author

tobz commented Oct 12, 2024

Released as part of metrics@v0.24.0/metrics-util@v0.18.0.

@tobz tobz removed the S-awaiting-release Status: awaiting a release to be considered fixed/implemented. label Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-core Component: core functionality such as traits, etc. E-simple Effort: simple. T-ergonomics Type: ergonomics.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Routing more than one pattern to the same Recorder
3 participants