-
-
Notifications
You must be signed in to change notification settings - Fork 483
Description
Summary
Change CryptoRng such that it can be used as a random number generator through a trait object, by making it a subtrait of RngCore.
This would break existing CryptoRng implementations, which were previously not implementing RngCore, but those were likely of limited use.
Details
Change the CryptoRng trait from this
pub trait CryptoRng {}to this
pub trait CryptoRng: RngCore {}Motivation
Currently the use of RngCore is supported in trait objects, however because of how trait objects are implemented, it is not possible to use CryptoRng in addition in the trait object, thus making it impossible to actually use a CryptoRng as a random number generator in trait objects.
This change is really small and likely has very little negative impact on users who don't need this change, but it can enable another way to use the API for users who do need it.
Alternatives
-
Add a
CryptoRngCoretrait to therand_corecrate:trait CryptoRngCore: RngCore + CryptoRng {} impl<T: RngCore + CryptoRng> CryptoRngCore for T {}
This would allow users to use
RngCore + CryptoRngtypes through trait objects as well, but at the cost of an additional trait in the (I presume intentionally) smallrand_corecrate. -
Do nothing and let users implement the
CryptoRngCoretrait above if they need it.This allows them to use
RngCore + CryptoRngtypes through trait objects, but since it isn't a unified solution, multiple equivalent traits with the exact same purpose and definition might pop up over time.Optionally this pattern could also be documented in the
CryptoRngtrait.