Show u8 slice in hex representation

后端 未结 3 464
清酒与你
清酒与你 2020-11-28 14:26

I need to convert &[u8] to a hex representation. For example [ A9, 45, FF, 00 ... ].

The trait std::fmt::UpperHex is not i

3条回答
  •  死守一世寂寞
    2020-11-28 14:41

    There's a crate for this: hex-slice.

    For example:

    extern crate hex_slice;
    use hex_slice::AsHex;
    
    fn main() {
        let foo = vec![0u32, 1, 2 ,3];
        println!("{:02x}", foo.as_hex());
    }
    

提交回复
热议问题