spacegate_kernel/utils/
schema_port.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
macro_rules! schema_port {
    ($($schema: literal => $port: literal)*) => {
        #[allow(unreachable_patterns)]
        pub fn schema_to_port(schema: &str) -> Option<u16> {
            match schema {
                $(
                    $schema => Some($port),
                    _ => None,
                )*
            }
        }
        #[allow(unreachable_patterns)]
        pub fn port_to_schema(port: u16) -> Option<&'static str> {
            match port {
                $(
                    $port => Some($schema),
                    _ => None,
                )*
            }
        }
    };
}

schema_port! {
    "http" => 80
    "ws" => 80
    "https" => 443
    "wss" => 443
    "grpc" => 50051
}