rocket/request/
atomic_method.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use crate::http::Method;

pub struct AtomicMethod(ref_swap::RefSwap<'static, Method>);

impl AtomicMethod {
    #[inline]
    pub fn new(value: Method) -> Self {
        Self(ref_swap::RefSwap::new(value.as_ref()))
    }

    #[inline]
    pub fn load(&self) -> Method {
        *self.0.load(std::sync::atomic::Ordering::Acquire)
    }

    #[inline]
    pub fn set(&mut self, new: Method) {
        *self = Self::new(new);
    }

    #[inline]
    pub fn store(&self, new: Method) {
        self.0.store(new.as_ref(), std::sync::atomic::Ordering::Release)
    }
}

impl Clone for AtomicMethod {
    fn clone(&self) -> Self {
        let inner = self.0.load(std::sync::atomic::Ordering::Acquire);
        Self(ref_swap::RefSwap::new(inner))
    }
}