Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd trait SampleRng: Rng and related doc #244
Conversation
This comment has been minimized.
This comment has been minimized.
|
Wacky idea: we could rename This would provide a nice split between front-end and back-end functionality, but I think overall would be confusing and not so useful (I generally disapprove of using the same name for different things in different namespaces). As I said, wacky idea. |
This comment has been minimized.
This comment has been minimized.
|
Is that helpful? Afaik, specialization cannot violate crate boundaries, right? I.e. Afaik, there are no sensible arguments why separating There might be arguments in favor of a slimmer |
pitdicker
approved these changes
Jan 25, 2018
|
After seeing your commit, but before looking at it closely I thought the extra trait provides a nice separation between front- and back-end. There really is a difference between the methods that make sense for an RNG to implement, and the methods that are best for user code. I would also like to see The changes and documentation look good to me. Is |
This comment has been minimized.
This comment has been minimized.
|
@burdges If the You do make two good arguments, boilerplate and documentation. I think |
This comment has been minimized.
This comment has been minimized.
|
@burdges the wacky idea was two separate traits, both named If we were to move some distributions code out to I'm not convinced about whether or not we need a separate
There will also be a There have already been a couple of suggestions to add a |
This comment has been minimized.
This comment has been minimized.
|
Your statement that " I'd almost agree the separation stops being quite so harmful for documentation if users almost never want functions from Are we clear on the relationship between We must remember that If the Instead, if we have I still think even if crate separation works it brings only needless constraints and pain. It's easiest to design without crate separation and then ask if your design splits cleanly afterwards. |
This comment has been minimized.
This comment has been minimized.
|
If documentation requires clicking through to the source, that's a deficiency in the documentation, in my opinion. That does sometimes happen but I'm not sure it's something we need to design around?
That's what's in this PR (plus the "wacky renames"), yes. I see your point about I'm not really sure whether users should prefer to use (core)
It fits the constraints we already have, except for this PR and the separate |
This comment has been minimized.
This comment has been minimized.
|
I tried adding a fn try_fill<T: AsByteSlice + ?Sized>(&mut self, dest: &mut T) -> Result<(), Error> { ... }and found:
The same method can be added to Does this count as motivation for this PR? Of course a generic |
This comment has been minimized.
This comment has been minimized.
|
My mistake, the above is because But this brings us to a more important point: generic methods like (Note: |
This comment has been minimized.
This comment has been minimized.
|
To confuse this topic even more, (&mut r).gen::<i32>();I don't understand how this works; presumably it forces r.gen::<i32>();
However, this syntax does work with this PR (also in my |
dhardy
added some commits
Jan 29, 2018
dhardy
added
the
E-question
label
Feb 7, 2018
This was referenced Feb 10, 2018
This comment has been minimized.
This comment has been minimized.
|
After some more investigation, I finally understand how impl<'a, R: ?Sized> Rng for &'a mut R where R: Rng { ... }Which can be specialised as: impl<'a> Rng for &'a mut Rng { ... }This provides a Note that we could change Conclusion: if we do not wish to add this extension trait, it appears reasonable to forgo direct support for dynamic dispatch on |
This comment has been minimized.
This comment has been minimized.
|
Rebasing #256 without this PR is very easy. So the question here appears to be is it worth adding an extension trait (a) to simplify syntax with dynamic dispatch and (b) to allow I think I agree with @burdges now that unless we have a real need for a separate |
dhardy
referenced this pull request
Feb 15, 2018
Closed
Distributions without direct dynamic dispatch #261
This comment has been minimized.
This comment has been minimized.
KodrAus
commented
Feb 15, 2018
|
One reason to split out a |
This comment has been minimized.
This comment has been minimized.
|
A stable back-end would allow stable PRNG/entropy source crates to be published sooner — but most consumers are indeed on the front-end. In reply to your other post about Serde's type erasure, I don't think adding an |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I think |
This comment has been minimized.
This comment has been minimized.
|
That's a moot point because |
This comment has been minimized.
This comment has been minimized.
|
I'm now tempted to rename I still like the idea of an extension trait because it separates what RNGs are supposed to implement and what they are not (e.g. backends should not be modifying |
This comment has been minimized.
This comment has been minimized.
KodrAus
commented
Feb 18, 2018
|
Hmm, it's true Bikeshedding the name aside I think the trait separation is fine too because it simplifies the mechanics of the |
This comment has been minimized.
This comment has been minimized.
|
Oh, good, sounds like we have mostly positive support for this change. To go back to the bike-shedding, I'm tempted to go with @newpavlov's suggestion: |
This comment has been minimized.
This comment has been minimized.
KodrAus
commented
Feb 18, 2018
|
As far as colours for bikesheds go, |
This comment has been minimized.
This comment has been minimized.
|
Then I will close in favour of #265. |
dhardy commentedJan 25, 2018
Move high-level
Rngfunctionality to an extension trait. See documentation here.This change is necessary to keep a similar interface for users while allowing a separate
rand-corecrate. Note that users often won't need to importRngat all, as many of the examples and theseqmodule show.Related:
Sample, but usingSampleRngis consistent with other extension-traits and perhaps less confusingnext_f32andnext_f64fromRng. That may or may not happen; it's not necessary for this change or therand-coresplit, and those are definitely low-level methods.Rand,SampleandIndepedentSampleall useRng, notSampleRngstill. That could change but would be a breaking change (since all the above may be replaced by a singleDistributiontrait, we can make the change then). I'm not certain which is best; possiblySampleRngsince this eliminates the need to importRngin many cases?Also, @burdges said recently he was against this trait and the
rand-coresplit. I don't think usage will be much different for end users (if anything, documentation is improved by separating front- and back-end functionality) and several people have requestedrand-coreso I think overall this is a win.