orx_concurrent_option/
drop.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use crate::{
    concurrent_option::ConcurrentOption,
    states::{RESERVED, SOME},
};
use core::sync::atomic::Ordering;

impl<T> Drop for ConcurrentOption<T> {
    #[allow(clippy::panic)]
    fn drop(&mut self) {
        match self.state.load(Ordering::Relaxed) {
            SOME => {
                let x = unsafe { &mut *self.value.get() };
                unsafe { x.assume_init_drop() };
            }
            RESERVED => {
                panic!("ConcurrentOption is dropped while its value is being written.")
            }
            _ => {}
        }
    }
}