random_fast_rng/
thread.rs

1use FastRng;
2
3use core::ops::{Deref, DerefMut};
4
5/// A shim that points to the global `FastRng` instance. isn't safe for multi-threading.
6///
7/// This struct is created by [`thread_local()`](../struct.FastRng.html#method.thread_local)
8pub struct ThreadFastRng(*mut FastRng);
9
10impl Deref for ThreadFastRng {
11    type Target = FastRng;
12
13    fn deref(&self) -> &Self::Target {
14        unsafe { &*self.0 }
15    }
16}
17
18impl DerefMut for ThreadFastRng {
19    fn deref_mut(&mut self) -> &mut Self::Target {
20        unsafe { &mut *self.0 }
21    }
22}
23
24pub trait FromRawPtr<T> {
25    fn from_ptr(ptr: *mut T) -> Self;
26}
27
28impl FromRawPtr<FastRng> for ThreadFastRng {
29    fn from_ptr(ptr: *mut FastRng) -> ThreadFastRng {
30        ThreadFastRng(ptr)
31    }
32}