codegenr_lib/helpers/
math.rs

1use handlebars::handlebars_helper;
2
3pub const HEX: &str = "hex";
4
5/// Return the hexadecimal representation of the integer value
6/// ```
7/// # use codegenr_lib::helpers::*;
8/// # use serde_json::json;
9/// assert_eq!(
10///   exec_template(serde_json::Value::Null, "{{hex 42}}"),
11///   "0x2a"
12/// );
13/// assert_eq!(
14///   exec_template(json!({ "value": 42 }), "{{hex value}}"),
15///   "0x2a"
16/// );
17/// ```
18pub fn hex(v: i64) -> String {
19  format!("0x{:x}", v)
20}
21handlebars_helper!(Hex: |v: i64| hex(v));