-
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
Restrict BlockRngCore::Item
type?
#305
Comments
This doesn't work: impl<C: BlockRngCore> From<<C as BlockRngCore>::Error> for Error {
fn from(e: <C as BlockRngCore>::Error) -> Error {
e.into()
}
} yields:
The error surprises me, but it's not really want we want anyway. |
What am I missing? The above impl I tried is stupid; instead one should use
Is this perhaps just the compiler's type-constaint prover giving up? |
Interesting problem, but.. I suggested
Also I'd expect |
At least two more options: Just use macros for any generic impls that require the
|
The impl for The impl for |
Is there a branch I can play with that's fairly close to this already? Alsi I think my "ugly" version does not really help much. |
The current master, look in the |
I'm suspicious about all these manual optimizations, like maybe some lighter weight optimizations achieve the same. I cannot point to anything concrete right now though. I worried slightly about what the correct endianness behavior should be here. We've some PRNG whose implementation is defined internally in terms of a It appears index counts |
Is In my opinion, you should strip out this |
Anyways.. I'd say drop the I suspect
|
Good point about Endianness; we say in the doc that PRNGs can define this in their impls, but all the helper functions and I'm not sure how Yes, |
Talking about specialisation, it might be possible to get very radical and redefine pub trait RngCore {
type Results: details::ResultRestriction;
type Error: Display + Into<Error>;
type Buffer: details::BufferRestriction;
fn generate() -> Result<Self::Results, Self::Error>;
} (where It might be possible to implement all generators using this interface with similar optimisation to what we have today — except that |
In fact, we've over constrained ourselves here because we imagine the constraints go roughly: We should At first blush, these sound contradictory but actually they present no problem because
We could even fold |
I think It's |
How about this?
|
I don't want to make big changes now if it's not necessary. Is there anything you think we should definitely do before the next release? See #232 (comment) |
IMO it makes little sense to further investigate this before Specialization is available. Of course by then we will probably have hit 1.0 and not want major changes (though we don't really want them now either: we have been accused of excessive API churn multiple times. Therefore, and since this has seen little interest in over a year, I think it unlikely we would ever land these suggestions (at least before 2.0) and best to close the issue, though of course further contributions are welcome. |
@burdges had an idea, looking something like:
This should allow the impl of
RngCore
forReseedingRng
to be properly generic:But there's a catch I haven't found a solution for: if we do
then Rustc doesn't understand that there are any bounds on the
Item
type, making the implementation impossible; if instead we dothen the generic impl for
ReseedingRng
doesn't work.It seems to me that Rustc needs more flexible handling of generics to give us a solution here?
The text was updated successfully, but these errors were encountered: