Created
February 21, 2024 04:05
-
-
Save computermouth/d82f7827201fab655170a0dbef8f792a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(PartialEq)] | |
enum Methods { | |
ALL, | |
GET, | |
HEAD, | |
POST, | |
PUT, | |
DELETE, | |
CONNECT, | |
OPTIONS, | |
TRACE, | |
PATCH, | |
} | |
impl std::ops::BitOr for Methods { | |
type Output = usize; | |
fn bitor(self, rhs: Self) -> Self::Output { | |
use Methods::*; | |
if self == ALL || rhs == ALL { | |
return 0; | |
} | |
let lo = match self { | |
GET => 1 << 0, | |
HEAD => 1 << 1, | |
POST => 1 << 2, | |
PUT => 1 << 3, | |
DELETE => 1 << 4, | |
CONNECT => 1 << 5, | |
OPTIONS => 1 << 6, | |
TRACE => 1 << 7, | |
PATCH => 1 << 8, | |
ALL => unreachable!(), | |
}; | |
let ro = match rhs { | |
GET => 1 << 0, | |
HEAD => 1 << 1, | |
POST => 1 << 2, | |
PUT => 1 << 3, | |
DELETE => 1 << 4, | |
CONNECT => 1 << 5, | |
OPTIONS => 1 << 6, | |
TRACE => 1 << 7, | |
PATCH => 1 << 8, | |
ALL => unreachable!(), | |
}; | |
lo | ro | |
} | |
} | |
fn main() { | |
println!("Hello, {}!", Methods::GET | Methods::POST); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment