Skip to content

Instantly share code, notes, and snippets.

@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; )*
@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 / taproot.rs
Last active May 21, 2022
taproot.rs
View taproot.rs
// Bitcoin Dev Kit
// Written in 2021 by Alekos Filini <alekos.filini@gmail.com>
//
// Copyright (c) 2020-2021 Bitcoin Dev Kit Developers
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
// You may not use this file except in accordance with one or both of these
// licenses.