Skip to content

Instantly share code, notes, and snippets.

@PsychedelicShayna
Created October 18, 2023 22:14
Show Gist options
  • Save PsychedelicShayna/ed4ecf9b13f51db3e062b73466b80dcd to your computer and use it in GitHub Desktop.
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?
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