Created
October 18, 2023 22:14
-
-
Save PsychedelicShayna/ed4ecf9b13f51db3e062b73466b80dcd to your computer and use it in GitHub Desktop.
Because seriously, why is `type` the only approximate keyword when it just acts like a #define? How about an actual type definition?
This file contains 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
macro_rules! typedef { | |
($name:ident, $type:ty) => { | |
#[derive(Debug, Clone)] | |
struct $name($type); | |
impl From<$type> for $name { | |
fn from(value: $type) -> Self { | |
$name(value) | |
} | |
} | |
impl From<$name> for $type { | |
fn from(value: $name) -> Self { | |
value.0 | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment