rocket/request/atomic_method.rs
1use std::sync::atomic::{AtomicU8, Ordering};
2
3use crate::http::Method;
4
5pub struct AtomicMethod(AtomicU8);
6
7impl AtomicMethod {
8 #[inline]
9 pub fn new(value: Method) -> Self {
10 Self(AtomicU8::new(value as u8))
11 }
12
13 #[inline]
14 pub fn load(&self) -> Method {
15 Method::ALL_VARIANTS[self.0.load(Ordering::Acquire) as usize]
16 }
17
18 #[inline]
19 pub fn set(&mut self, new: Method) {
20 *self = Self::new(new);
21 }
22
23 #[inline]
24 pub fn store(&self, new: Method) {
25 self.0.store(new as u8, Ordering::Release)
26 }
27}
28
29impl Clone for AtomicMethod {
30 fn clone(&self) -> Self {
31 Self(AtomicU8::new(self.0.load(Ordering::Acquire)))
32 }
33}