dhardy / rand

http://doc.rust-lang.org/rand
Other
2 stars 2 forks source link

Replace `rand_core::impls` module with macros? #38

Closed dhardy closed 6 years ago

dhardy commented 6 years ago

Is it possible to replace the functions in rand_core::impls with some kind of derive macros? E.g. it would be nice if OsRng could do something like follows (instead of this).

#[derive(impl_from_try_fill)]
pub struct OsRng(imp::OsRng);

impl Rng for OsRng {
    fn try_fill(&mut self, v: &mut [u8]) -> Result<(), Error> {
        self.0.try_fill(v)
    }
}

Proceedural macros may already provide all we need for this? Also see the book article, and the procedural masquerade crate.

dhardy commented 6 years ago

Note: those "impl" functions are modular on purpose; some flexibility is still needed.

Most likely Rng will have a primary implementation in terms of just one of the Rng functions, but in several places it may be possible to write a more optimal implementation of another function using internal details (e.g. #36).

pitdicker commented 6 years ago

It could be an ergonomic win, but there are really not that many Rng implementations. Is it worth the effort?

Edit: I see this bug is on reddit/r/rust. Not to discourage anyone. If this seems like a nice project, go for it! 😃

dhardy commented 6 years ago

https://github.com/rust-lang-nursery/rand/pull/292 implements a less flexible derive, and may not get merged due to little use. There seems little incentive to develop more macros for this.