Skip to content

Instantly share code, notes, and snippets.

@afilini
afilini / main.rs
Created Jan 30, 2020
Runtime templates
View main.rs
#[derive(Debug)]
struct A {
val: u32,
}
#[derive(Debug)]
struct B {
val: String,
}
@afilini
afilini / main.rs
Created Jan 29, 2020
Generic amount types in Rust
View main.rs
use std::collections::BTreeMap;
#[derive(Debug)]
struct LiquidAmount(BTreeMap<String, u64>);
type BitcoinAmount = u64;
macro_rules! liquid_amount {
( $( $key:expr => $val:expr ),* ) => {{
let mut map = BTreeMap::new();
$( *map.entry($key.into()).or_insert(0) += $val; )*