-
Notifications
You must be signed in to change notification settings - Fork 432
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 CryptoRngCore
to support CryptoRng
trait objects
#1187
Conversation
I think we should introduce |
@newpavlov Would |
@vks No, it will not replace it. I suggest introducing both #[deprecated(since="0.8.5", note="use `CryptoRngCore` or `CryptoBlockRngCore` instead")]
trait CryptoRng {}
trait CryptoBlockRngCore: BlockRngCore {}
trait CryptoRngCore: RngCore {}
impl<T: BlockRngCore> RngCore for BlockRng<T> { .. }
impl<T: CryptoBlockRngCore> CryptoRngCore for BlockRng<T> {}
// now we have two options for blanket impls
// first:
impl<T: CryptoRng + BlockRngCore> CryptoBlockRngCore for T {}
impl<T: CryptoRng + RngCore> CryptoRngCore for T {}
// second:
impl<T: CryptoBlockRngCore> CryptoRng for T {}
impl<T: CryptoRngCore> CryptoRng for T {} With the first blanket impls, existing crates would implement the new traits automatically, but RNG crates would have to keep the |
@newpavlov I think your approach has the disadvantage that it's not possible to have a trait object that supports both |
It's not a disadvantage, but an intentional design choice. Why do you think we need a trait object which supports both? In my opinion, ideally Motivation of the original issue is fully covered by the |
You are right, they are used in a mutually exclusive way at the moment, having a trait object for both does not make sense. Let me reframe: Relative to the current PR, you are proposing to remove the |
@newpavlov first I presume you meant to write From today's perspective,
Only one of these options is not a breaking change for all crypto-RNGs, so is there really a good reason to choose any other option? |
It already works on nightly, but who knows when it will be stabilized (see rust-lang/rust#65991 ). |
The only purpose of the
Ah, yes. You are right. I forgot about it since I never needed something similar myself. Personally I think such case will be overwhelmingly rare in practice, but I agree it's a valid use-case. As I've outlined earlier, I would prefer to introduce |
Rare, yes, but it's the use-case behind #1143.
But why? As I said above, is there really a reason to choose anything other than the least-breaking option? Your option implies people must either put up with deprecation warnings or update and be incompatible with downstream crates which haven't updated from |
I have a different understanding. The author himself has proposed the sub-trait approach without any mention of upcasting. It was mentioned first by you in the reply to @burdges' comment. But either way, I agree that it's worth to have the upcast method just in case.
Because I think it's a more consistent API which we should have in |
I don't think we need a stop-gap since there is no pressing need to solve #1143, hence from my point of view we can either implement your solution in Also from my point of view: it is nicer for users to have a So, maybe we need some more perspectives here? |
I agree that the benefits of consistency don't outweigh the churn due to breaking changes and the additional required boilerplate, especially for such a niche feature. Less users having to touch the new API is also an advantage. If we really want to make everything more consistent anyway, we can still do that later with a breaking change. |
I disagree. AFAIK currently most (if not all) users of IIRC the only reason why the current |
A marker trait still has the advantage that it saves users from having to implement the boilerplate for upcasting support. We would lose that advantage by turning I'm still not convinced that we need |
@vks
As I wrote earlier, it's needed solely for the blanket impl on the Yes, we could make |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering the arguments, I'm tempted to accept this now, and reconsider breaking changes later (especially after Rust supports trait-object upcast).
Fixes #1143.