Skip to content
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

Rand core changes #419

Merged
merged 6 commits into from
May 3, 2018
Merged

Rand core changes #419

merged 6 commits into from
May 3, 2018

Conversation

pitdicker
Copy link
Contributor

@pitdicker pitdicker commented Apr 29, 2018

I forgot to change BlockRng64::inner to return a reference and to add inner_mut in #325 (comment).

This PR also copies the index and generate_and_set methods from #374 to BlockRng64, and updates the changelog.

Edit: the build will fail because I added #![deny(missing_docs)]. The offending line is fixed in #374; as it gets fixed anyway it seemed nice to prevent a merge conflict.

@pitdicker
Copy link
Contributor Author

Forgot about #376, will add that to this PR later today.

Copy link
Member

@dhardy dhardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can't merge this until after #374 anyway so still some time to make changes — it may end up being better if I pull some of these commits into that PR however.

- Enable the `std` feature by default. (#409)
- Change `BlockRng64::inner` and add `BlockRng64::inner_mut` to mirror `BlockRng`. (#419)
- Add `BlockRng{64}::index` and `BlockRng{64}::generate_and_set`. (#374, #419)
- Add `AsMut<[Self::Item]>` bound to `BlockRngCore::Results` (future-proofing). (#419)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is technically a breaking change, I think it would be better to rephrase as "Change BlockRngCore::Results bound to also require AsMut<[Self::Item]>".

And since we have two small breaking changes shall we call this 0.2.0 instead?

/// Return a mutable reference the wrapped `BlockRngCore`.
pub fn inner(&mut self) -> &mut R {
pub fn inner_mut(&mut self) -> &mut R {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we must expose both inner and inner_mut and we will always have exactly one "core", there doesn't seem to be any advantage over just making core a pub field (which would be nicer syntactically). Since we have to make a breaking change here anyway (and probably no other users will be affected yet), shall we just do this?

For the other fields there is some advantage in keeping them private, but not really for core I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters much one way or the other. It feels a little strange to me to have one public field, but the rest private.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works reasonably well IMO — typical usage is like ChaChaRng(BlockRng { core: ChaChaCore, .. }); i.e. the outer type is free to access the inner type however is deemed fit, whereas the other fields are not quite so straightforward.

}

impl<R: BlockRngCore<Item=u64>> RngCore for BlockRng64<R>
where <R as BlockRngCore>::Results: AsRef<[u64]>
where <R as BlockRngCore>::Results: AsRef<[u64]> + AsMut<[u64]>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need the new bound here? (Also for BlockRng above.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially tried to add the bound only on BlockRngCore, but it doesn't compile without the bound in a few more places.

@pitdicker
Copy link
Contributor Author

Is this PR ready to be merged? We can always make the field public later, right?

@dhardy
Copy link
Member

dhardy commented May 3, 2018

Yes, this is ready except that CI now fails. Can you fix and merge?

Sorry, seems to be fine.

@dhardy dhardy merged commit aaaf03f into rust-random:master May 3, 2018
@pitdicker pitdicker deleted the rand_core_changes branch May 3, 2018 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants