-
Notifications
You must be signed in to change notification settings - Fork 431
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
Implement Rng for Box with alloc feature #227
Conversation
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.
I was a bit shocked by the size of this PR, but on closer look I like what you've done!
src/lib.rs
Outdated
@@ -625,7 +625,9 @@ impl<'a, R: ?Sized> Rng for &'a mut R where R: Rng { | |||
} | |||
} | |||
|
|||
#[cfg(feature="std")] | |||
#[cfg(all(feature="alloc", not(feature="std")))] | |||
use alloc::boxed::Box; |
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.
I'd prefer if you put the use
statement above, near #[cfg(feature="std")] use std::rc::Rc;
.
src/reseeding.rs
Outdated
// Sanity test: if we've gotten here, `fill_bytes` has not infinitely | ||
// recursed. | ||
assert_eq!(v.len(), FILL_BYTES_V_LEN); | ||
|
||
// To test that `fill_bytes` actually did something, check that the | ||
// average of `v` is not 0. | ||
let mut sum = 0.0; |
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.
If you're going to tidy up, might as well just compare the sum here instead of average.
Oh, yes, but is the test framework even available? I was wondering about |
That was my thought also, but I turns out to work. With everything commented out the PRNG tests run successfully. |
960a4e0
to
a818a01
Compare
a818a01
to
4828506
Compare
I have replaced all uses of That took care of just about all errors left. Testing for
I did not replace |
(I rebased the first 5 commits, I believe a documentation change in chacha made it unmergable. But otherwise didn't touch them) |
Nice work! I agree, I don't think it's worth changing the doc-tests. One final thing to do: add those new tests to CI. |
Implement Rng for Box with alloc feature
As discussed in #225 (comment).
I thought to run
cargo test --no-default-features --feature=alloc
, but that did not work. Endless compiler warnings.I have included a couple a couple of commits that fix some of the tests that depend on needless memory allocations. Still about 40 compiler errors to go, most of which have to do with
tread_rng
not being available inlib.rs
.The test in
lib.rs
are where most of the remain problems are, and I didn't feel like fixing them at the moment. Those tests date from 5/6 years ago whenrand.rs
was the only file and things were very different. Several are now part of submodules, or could use a close look.So testing on
no_std
does not work yet, but I hoped to leave that for another PR.