rust-random / getrandom

A small cross-platform library for retrieving random data from (operating) system source
Apache License 2.0
275 stars 180 forks source link

Enforce OS errors are in the allowed range. #441

Closed briansmith closed 4 months ago

briansmith commented 4 months ago

Avoid the From<NonZeroU32> implementation in favor of a constructor that centralizes all the range checking in one place. Consistently use ERRNO_NOT_POSITIVE for nonpositive values and Self::UNEXPECTED for too-large values.

Besides being more consistent in the range checking, this also reduces the boilerplate in callers, which makes it easier to maintain the ports to less-common operating systems.

briansmith commented 4 months ago

I updated this to be cleaner. I also removed the #[cold] since that's an unrelated change.

newpavlov commented 4 months ago

What about my suggestion above?

briansmith commented 4 months ago

What about my suggestion above?

Sorry, I don't see it. Maybe it is still a draft?

newpavlov commented 4 months ago

Oh, oops. You are right.