ore/metrics: implement Borrow for drop wrapper types#19929
Conversation
|
I see in the documentation of the If not, I think we should also add a comment in the definition of the struct warning future developers that they should not add a derive for any of |
I don't think that would work. The goal would be to specify a trait bound like: ... and then be able to pass both Adding a comment is a good idea! |
|
Alternatively, we could just invent our own But if we decide that the |
897a602 to
e0417b3
Compare
This commit adds `Borrow` implementations to the wrapper types `DeleteOnDropHistogram`, `DeleteOnDropCounter`, and `DeleteOnDropGauge`. This makes it possible to write code that is generic over both the prometheus type and the wrapped type. The existing `Deref` impl does not work for this.
e0417b3 to
7d32407
Compare
|
I've added the comments as suggested by @petrosagg. In Slack we seem to have arrived at a rough consensus that the |
|
TFTR! |
This PR adds
Borrowimplementations to the wrapper typesDeleteOnDropHistogram,DeleteOnDropCounter, andDeleteOnDropGauge.This makes it possible to write code that is generic over both the prometheus type and the wrapped type. The existing
Derefimpl does not work for this.Slack thread for context.
Blocks #19964.
Motivation
Make it possible to write code that is generic over both
GenericGaugeandDeleteOnDropGauge.Tips for reviewer
@petrosagg points out that perhaps we shouldn't do this because
Borrowis reserved for smart pointers. I would have called theDeleteOnDrop*wrappers smart pointers, but I'm also not clear about the definition. In any case, those types already implementDeref, which is also a smart-pointer trait.Checklist
$T ⇔ Proto$Tmapping (possibly in a backwards-incompatible way), then it is tagged with aT-protolabel.