View halve.rs
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
/// strategy: | |
/// - first copy the list of exprs -- the copy will just be used as a counter | |
/// - then, starting with all the exprs in a "left" list and an empty "right" list: | |
/// - move one expr at a time from "left" to "right", and decrement the counter _twice_ | |
/// - when the counter is zero, the halving is complete | |
/// - if there were an odd number of exprs, a compile error tells you about it | |
/// the macro is in continuation passing style, so you pass in a macro invocation and it will be called | |
/// twice, first with the "left" and then with the "right" (enclosed in square brackets) inserted as the last argument | |
macro_rules! halve { | |
// internal rules |
View index.html
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<link rel="stylesheet" href="http://cmx.io/v/0.1/cmx.css"> | |
<script src="http://cmx.io/v/0.1/cmx.js" charset="utf-8"></script> | |
<style>.cmx-user-scene4 .cmx-text-border .cmx-path {stroke: orange}</style> | |
<body> | |
<div style="max-width:1200px; -webkit-transform:rotate(0deg)"> | |
<scene id="scene1"> | |
<drawing t="translate(0,31)"> |
View playground.rs
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
#![feature(trace_macros)] trace_macros!(true); | |
macro_rules! doc_items { | |
(@distribute $docs:tt $($item:item)*) => { | |
$(doc_items!(@output $docs $item);)* | |
}; | |
(@output [$($doc:expr),*] $item:item) => { | |
$(#[doc=$doc])* | |
$item | |
}; |
View main.rs
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
let (device, factory) = | |
if let Ok((d, f)) = panic::catch_unwind(|| { gfx_device_gl::create(epoxy::get_proc_addr) }) { | |
(d, f) | |
} else { | |
return "ERROR"; | |
}; |
View playground.rs
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! siaf { | |
(|$($parm:ident),* $(,)*| $body:expr) => {{ | |
/* ensure no captures */ let closure: fn($($parm: _),*)->_ = |$($parm),*| $body; | |
(closure)($($parm),*) | |
}} | |
} | |
fn compute_g(a: i32, b: i32, c: i32) -> i32 { | |
let d = siaf!(|a, b| a + c); | |
let (e, f) = siaf!(|d| (d - 1, d + 1)); |
View playground.rs
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
#![feature(trace_macros)] trace_macros!(true); | |
/// Given N tokens, recurses N times to generate N unique identifiers | |
/// then calls you back at the given macro | |
macro_rules! idents { | |
// finished recursing, do the callback | |
(@rec [] -> $ids:tt $mac:ident!($($params:tt)*)) => { | |
$mac!($($params)* $ids) | |
}; | |
// consume one token and generate one identifier |
View error.rs
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
warning: unreachable pattern | |
--> src/routes.rs:66:1 | |
| | |
66 | / handle_login! { | |
67 | | #[get("/<date>/<flow>/<idx>")] | |
68 | | pub fn episode/episode_login(user: User, users: State<ActiveUsers>, date: Datestamp, flow: Option<FlowType>, idx: u32) -> Template { | |
69 | | let flow = flow.ok_or(ErrorKind::BadParam("invalid flow type"))?; | |
... | | |
132 | | } | |
133 | | } |
View playground.rs
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
/// This auxiliary macro generates an ident for each argument passed to it, | |
/// and then calls another macro back with the generated idents. | |
macro_rules! gensym { | |
// base case: we send all the collected idents back to the other macro | |
(@go $callback:ident ($($args:tt)*) ($($i:ident)*)) => { | |
$callback!($($args)* $($i)*) | |
}; | |
// recursion: here, we add in a new ident named "x" (but distinct from every other "x") | |
(@go $callback:ident $args:tt ($($i:ident)*) $head:tt $($tail:tt)*) => { |
View twixt.rs
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! twixt { | |
(($cond:expr; $after:expr) { $($body:tt)* } else { $($els:tt)* }) => {{ | |
if $cond { | |
struct Doop; | |
impl Drop for Doop { fn drop(&mut self) { $after; } } | |
let _d = Doop; | |
$($body)* | |
} else { | |
$($els)* | |
} |
View main.rs
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
use std::process::Command; | |
fn main() { | |
println!("{}", git_name().unwrap_or("".to_string())); | |
} | |
pub fn git_name() -> Option<String> { | |
if let Ok(output) = Command::new("git") | |
.arg("config") |
NewerOlder