-
Notifications
You must be signed in to change notification settings - Fork 201
Allow into/from inner Arc conversions
#472
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: tyranron <[email protected]>
Signed-off-by: tyranron <[email protected]>
|
Thanks for the patch. I'm still slightly unconvinced on the I'd even say the It is my understanding that the correctness of this relies on |
This way, the people who really need this (like me), may not find it at all. To be honest, for my needs, adding
Not sure, I've understood you. You mean my use case, or the proposed API of
In my use case, I need to return to library users a type being essentially an |
|
I meant on the proposed API for the |
Ooops, I didn't notice that. Thought it was public as the type was Yup, that's unfortunate, as even for
Not yet. I'll craft the PR referring this one and write back. |
Overview
This PR adds:
into_arc_value()andfrom_arc_value()methods toGenericCounterandGenericGaugetypes. These methods areunsafeas allow bypassing counter/gauge semantics.into_arc_core()andfrom_arc_core()methods toHistogramtype. These methods are safe, as theHistogramCorepublic API doesn't allow bypassingHistogramsemantics in any way.#[repr(transparent)]attribute toGenericCounter,GenericGaugeandHistogram, so they can be safely transmuted into its innerArcand back.Motivation
While implementing the
metrics-prometheuscrate, I have the situation where themetricscrate requires the returned metric beingArc-wrapped (because returns to usersArc<dyn Trait>essentially), and so, pushing me to introduce a completely redundant allocation on the hot path accessing the metric, becauseprometheusmetric types haveArced semantics anyway.First, I've tried to approach this on the
metricscrate's side, but had no luck, as its API returnsArc<dyn Trait>to user code, so creating anArccannot be really bypassed here.Then, I've looked at
prometheusmetric type's structure and realized that I can unwrap it into its innerArc, and then, in theTraitimplementation, wrap back into the original metric type. The whole thing doesn't leave the library boundary, so users won't be able to misuse the unwrappedArcs anyhow.As the bonus, it will allow me to solve the synchronization issue from #471, but without exposing safe APIs to
prometheususers which do not follow metric type's semantics.Notes
this: Selfargument instead of justselfininto*methods, mimicking theArc::into_raw(), to additionally discourage library users from using those methods.Checklist
Tests are added(do we need ones here?)