dhardy / rand

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

Implicit error handling (#25) #40

Closed dhardy closed 6 years ago

dhardy commented 6 years ago

Add rand_core::impls::fill_via_try_fill with handling for errors.

I'm not completely happy about this but it does roughly meet the requirements in #25.

Using a global error counter is a bit weird, but seems better than adding a local error counter (e.g. ReadRng uses this impl, but can't actually emit the Transient error in any case).

In fact, no current code emits either Transient or NotReady.

Also, I think the best option for printing error causes when panicking is to log?

dhardy commented 6 years ago

Also: how should we handle NotReady?

This code sleeps for 10ms, except no_std provides no interface for this so in that case the code retries immediately. Do we have another option? Is busy-waiting acceptable?

dhardy commented 6 years ago

The second commit allows OsRng to return NotReady, in theory (Linux only, and only if getrandom is available). I don't know how to test this.

How does it interact with the implicit handling? Since OsRng is only available with std, it should loop with 10ms sleep intervals, in theory: possibly slightly more CPU usage and slightly more wait time, but probably insignificant.