Skip to content

Commit c65a653

Browse files
authored
Add ability to step on a lego (#25)
- Resolves #23
2 parents 63a0aae + d4c1bdc commit c65a653

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ debug = false
2424
default = []
2525
download-more-ram = ["ureq"]
2626
give-up = ["oorandom"]
27+
step-on-lego = ["oorandom"]
2728

2829
[[bench]]
2930
name = "transmute"

src/lib.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,35 @@ pub fn construct_fake_string(ptr: *mut u8, cap: usize, len: usize) -> String {
5252
crate::transmute::<_, String>(actual_buf)
5353
}
5454

55-
/// Good for job security.
56-
#[cfg(feature = "give-up")]
57-
pub fn give_up<T: 'static>() -> Box<T> {
55+
#[cfg(any(feature = "give-up", feature = "step-on-lego"))]
56+
fn seed() -> u64 {
5857
use std::time::SystemTime;
5958

59+
let seed = SystemTime::now()
60+
.duration_since(SystemTime::UNIX_EPOCH)
61+
.unwrap();
62+
63+
seed.as_secs()
64+
}
65+
66+
/// It can be fatal if you step hard enough.
67+
#[cfg(any(feature = "give-up", feature = "step-on-lego"))]
68+
pub fn step_on_lego() -> u32 {
69+
let mut rng = oorandom::Rand64::new(seed() as u128);
70+
71+
let lego = crate::transmute::<usize, &'static u32>(rng.rand_u64() as usize);
72+
73+
*lego
74+
}
75+
76+
/// Good for job security.
77+
#[cfg(any(feature = "give-up", feature = "step-on-lego"))]
78+
pub fn give_up<T: 'static>() -> Box<T> {
6079
let size = std::mem::size_of::<T>();
6180

6281
let mut v = Vec::with_capacity(size);
6382

64-
let mut rng = {
65-
let seed = SystemTime::now()
66-
.duration_since(SystemTime::UNIX_EPOCH)
67-
.unwrap();
68-
69-
oorandom::Rand32::new(seed.as_secs())
70-
};
83+
let mut rng = oorandom::Rand32::new(seed());
7184

7285
for _ in 0..size {
7386
v.push((rng.rand_u32() % 256) as u8);

0 commit comments

Comments
 (0)