Skip to content

Instantly share code, notes, and snippets.

@computermouth
Created February 21, 2024 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save computermouth/d82f7827201fab655170a0dbef8f792a to your computer and use it in GitHub Desktop.
Save computermouth/d82f7827201fab655170a0dbef8f792a to your computer and use it in GitHub Desktop.
#[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