Make CryptoRngCore trait imply CryptoRng as well
#1230
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I recently had a case where I needed to make an API that takes
&mut dyn (CryptoRng + RngCore). I didn't want to make my trait generic because it would greatly complicate some FFI situations.Since rust doesn't currently allow
dyn (CryptoRng + RngCore), I needed to make an extension trait that implies both of these, and, naturally, is implied for any object with both of these traits.It turns out that
randcrate already does almost the same thing withCryptoRngCore(which is actually what I named my extension trait).However the implementation in
randcrate is slightly different:CryptoRngCoreimpliesRngCorebut notCryptoRng.I can't see right now that there's a compelling use-case for it the way it's implemented right now: any place where I would write
&mut dyn CryptoRngCoremy code would also work if my function takes&mut dyn RngCore, sinceCryptoRngCoreprovides no additional functionality other than a function that converts self to&mut dyn RngCore. (But I could have started with that...)OTOH if
CryptoRngCoreimplies bothRngCoreandCryptoRngthen it's quite useful, because it works around the inability to makedyn (X + Y)in rust right now. Then I would just use the upstream version and drop my version.Let me know what you think. Thank you!