Skip to content

Instantly share code, notes, and snippets.

@jakobrs
Created June 17, 2022 16:46
Show Gist options
  • Save jakobrs/de9ae59248f772fd48945031f36291f3 to your computer and use it in GitHub Desktop.
Save jakobrs/de9ae59248f772fd48945031f36291f3 to your computer and use it in GitHub Desktop.
macro_rules! define_macros_inner {
($words:ident, $out:ident, $d:tt) => {
macro_rules! read {
() => {
$words.next().unwrap().parse().unwrap()
};
($t:ty) => {
$words.next().unwrap().parse::<$t>().unwrap()
};
($t:ty, $n:expr) => {
$words
.by_ref()
.take($n)
.map(|s| s.parse().unwrap())
.collect::<Vec<$t>>()
};
}
macro_rules! pln {
() => {
::std::io::Write::write_all(&mut $out, b"\n").unwrap();
};
($d($d arg:tt)*) => {
::std::io::Write::write_fmt(&mut $out, format_args!($d($d arg)*)).unwrap();
::std::io::Write::write_all(&mut $out, b"\n").unwrap();
};
}
macro_rules! p {
($d($d arg:tt)*) => {
::std::io::Write::write_fmt(&mut $out, format_args!($d($d arg)*)).unwrap();
};
}
};
}
macro_rules! define_macros {
($words:ident, $out:ident) => {
define_macros_inner!($words, $out, $);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment