libpenis/
lib.rs

1use std::sync::atomic::Ordering;
2
3//Creates the balls and dick head
4mod atomics {
5    use std::sync::atomic::AtomicUsize;
6
7    pub static BALLS: AtomicUsize = AtomicUsize::new(0);
8    pub static DICK_HEAD: AtomicUsize = AtomicUsize::new(0);
9}
10
11pub fn set_balls(balls: usize) {
12    atomics::BALLS.store(balls, Ordering::SeqCst);
13}
14
15pub fn set_dick_head(head: usize) {
16    atomics::DICK_HEAD.store(head, Ordering::SeqCst);
17}
18
19//The following 2 functions can be used to read values in a more clean way
20pub fn get_balls() -> usize {
21    atomics::BALLS.load(Ordering::SeqCst)
22}
23
24pub fn get_dick_head() -> usize {
25    atomics::DICK_HEAD.load(Ordering::SeqCst)
26}
27
28#[cfg(test)]
29mod tests {
30    use crate::{set_balls, set_dick_head, get_balls, get_dick_head};
31
32    #[test]
33    fn assign_and_read() {
34        set_balls(1);
35        set_dick_head(1);
36
37        let B = get_balls();
38        let D = get_dick_head();
39
40        if B==D {
41            println!("Success!");
42        } else {
43            panic!("Dick did not equal.");
44        }
45    }
46}