From 93f4a70f7fca8171d100c3867825a62b5dcc599b Mon Sep 17 00:00:00 2001 From: joboet Date: Fri, 17 Jul 2026 12:55:00 +0200 Subject: [PATCH] core: implement `Rng` for references --- library/core/src/random.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/core/src/random.rs b/library/core/src/random.rs index 7275b3c203b5c..1123e1949a02d 100644 --- a/library/core/src/random.rs +++ b/library/core/src/random.rs @@ -14,6 +14,15 @@ pub trait Rng { fn fill_bytes(&mut self, bytes: &mut [u8]); } +/// Implements `Rng` for mutable references to random number generators by +/// forwarding all methods to the referenced generator. +#[unstable(feature = "random", issue = "130703")] +impl<'a, R: Rng + ?Sized> Rng for &'a mut R { + fn fill_bytes(&mut self, bytes: &mut [u8]) { + R::fill_bytes(self, bytes); + } +} + /// A trait representing a distribution of random values for a type. #[unstable(feature = "random", issue = "130703")] pub trait Distribution {