]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/rand/os.rs
libstd: add a dummy field to `OsRng` to avoid out of module construction
[rust.git] / src / libstd / rand / os.rs
index c0eebe135c3ce2893bfed4eaa1b5331947a52689..c1e426602694a077fb7ed0fa85fd4f38107e06d9 100644 (file)
@@ -187,7 +187,10 @@ mod imp {
     /// - iOS: calls SecRandomCopyBytes as /dev/(u)random is sandboxed
     /// This does not block.
     #[allow(missing_copy_implementations)]
-    pub struct OsRng;
+    pub struct OsRng {
+        // dummy field to ensure that this struct cannot be constructed outside of this module
+        _dummy: (),
+    }
 
     #[repr(C)]
     struct SecRandom;
@@ -204,7 +207,7 @@ fn SecRandomCopyBytes(rnd: *const SecRandom,
     impl OsRng {
         /// Create a new `OsRng`.
         pub fn new() -> IoResult<OsRng> {
-            Ok(OsRng)
+            Ok(OsRng { _dummy: () })
         }
     }