Skip to content

Instantly share code, notes, and snippets.

macro_rules! enum_with_str_repr {
($enum_name:ident { $($variant:ident => $str:expr),* }) => {
#[derive(PartialEq, PartialOrd, Copy, Clone, Eq, Ord, Hash, Debug)]
pub enum $enum_name {
$(
#[doc=$str]
$variant,
)*
}
@killercup
killercup / Cargo.lock
Created May 8, 2017 12:21
extern crate in doctest
[root]
name = "playground"
version = "0.1.0"
dependencies = [
"serde_json 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dtoa"
version = "0.4.1"
macro_rules! externs {
( $name:ident with macros, $($rest:tt)* ) => {
externs!($x with macros);
externs!($($rest)*);
};
( $name:ident, $($rest:tt)* ) => {
externs!($name);
externs!($($rest)*);
};
( $name:ident with macros ) => {
@killercup
killercup / playground.rs
Last active January 20, 2017 18:49
gracefully_hysteria
macro_rules! graceful_hysteria {
($($stuff:tt)*) => {
{
use std::io::Write;
let _ = writeln!(::std::io::stderr(), $($stuff)*);
::std::process::exit(1);
}
}
}
fn fst<T1, T2>((t1, _t2): (T1, T2)) -> T1 {
t1
}
fn snd<T1, T2>((_t1, t2): (T1, T2)) -> T2 {
t2
}
fn main() {
let xs = vec![42, 43, 44, 45];
@killercup
killercup / Makefile
Created January 13, 2017 19:44
Auto Makefile CLI help
ARGS = $(filter-out $@,$(MAKECMDGOALS))
MAKEFLAGS += --silent
PROJECTNAME = foobar
.PHONY: help
.DEFAULT_GOAL := help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@killercup
killercup / playground.rs
Created January 12, 2017 20:53
Ping ALL the machines in a subnet
use std::collections::BTreeMap;
use std::net::Ipv4Addr;
use std::thread;
use std::process::{Command, Stdio};
fn main() {
let subnet: u8 = std::env::args()
.skip(1)
.next()
.unwrap_or("20".into())
#![allow(dead_code)]
/// Create method to access field of sub-resource
///
/// Similar to ActiveSupport's [`delegate`].
///
/// [`delegate`]: http://api.rubyonrails.org/classes/Module.html#method-i-delegate
///
/// # Limitations
///
macro_rules! w {
($($x:ident)+) => {
vec![$(stringify!($x),)*]
}
}
#[test]
fn ident_vec() {
assert_eq!(w![foo bar baz], vec!["foo", "bar", "baz"]);
}