actix_cors/
all_or_some.rs1#[derive(Debug, Clone, PartialEq, Eq)]
3pub enum AllOrSome<T> {
4    All,
6
7    Some(T),
9}
10
11impl<T> Default for AllOrSome<T> {
13    fn default() -> Self {
14        AllOrSome::All
15    }
16}
17
18impl<T> AllOrSome<T> {
19    pub fn is_all(&self) -> bool {
21        matches!(self, AllOrSome::All)
22    }
23
24    #[allow(dead_code)]
26    pub fn is_some(&self) -> bool {
27        !self.is_all()
28    }
29
30    pub fn as_ref(&self) -> Option<&T> {
32        match *self {
33            AllOrSome::All => None,
34            AllOrSome::Some(ref t) => Some(t),
35        }
36    }
37
38    pub fn as_mut(&mut self) -> Option<&mut T> {
40        match *self {
41            AllOrSome::All => None,
42            AllOrSome::Some(ref mut t) => Some(t),
43        }
44    }
45}
46
47#[cfg(test)]
48#[test]
49fn tests() {
50    assert!(AllOrSome::<()>::All.is_all());
51    assert!(!AllOrSome::<()>::All.is_some());
52
53    assert!(!AllOrSome::Some(()).is_all());
54    assert!(AllOrSome::Some(()).is_some());
55}