Skip to content

Instantly share code, notes, and snippets.

@1tgr
Created October 27, 2018 20:07
Show Gist options
  • Select an option

  • Save 1tgr/ab18761da711b3d8f95aa1bf95327880 to your computer and use it in GitHub Desktop.

Select an option

Save 1tgr/ab18761da711b3d8f95aa1bf95327880 to your computer and use it in GitHub Desktop.
enum Product {
"BTC-EUR",
"ETH-EUR",
"ETH-BTC",
}
let p: Product = Product!("BTC-EUR");
mod product {
struct "BTC-EUR";
struct "ETH-EUR";
struct "ETH-BTC";
impl Convention for "BTC-EUR" {
fn tick_size() -> f64 {
0.01
}
}
}
struct Visitor {
fn visit<C: Convention>() -> i32 {
-C::tick_size().log10() as i32
}
}
assert_eq!(2, product::visit_convention("BTC-EUR", Visitor));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment