format_hex

Function format_hex 

Source
pub fn format_hex<T, W: Write>(value: &Value<T>, writer: W) -> Option<Result>
Expand description

This can be used alongside crate::stringify::ToWriterBuilder::add_custom_formatter() (which itself is constructed via crate::stringify::to_writer_custom()). It will format as a hex string any unnamed composite whose values are all primitives in the range 0-255 inclusive.

ยงExample

use scale_value::{value,Value};
use scale_value::stringify::{to_writer_custom, custom_formatters::format_hex};

let val = value!({
    foo: (1u64,2u64,3u64,4u64,5u64),
    bar: (1000u64, 10u64)
});

let mut s = String::new();

to_writer_custom()
    .add_custom_formatter(|v, w| format_hex(v, w))
    .write(&val, &mut s)
    .unwrap();

assert_eq!(s, r#"{ foo: 0x0102030405, bar: (1000, 10) }"#);