hummer 0.2.0

Hummer is a set of utilities.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::io::{Error, ErrorKind};

pub fn hex_encode<T: AsRef<[u8]>>(src: T) -> String {
    faster_hex::hex_string(src.as_ref())
}

pub fn hex_decode(src: &str) -> Result<Vec<u8>, Error> {
    if src.is_empty() {
        return Ok(Vec::new());
    }

    let src = src.as_bytes();
    let mut ret = vec![0u8; src.len() / 2];
    faster_hex::hex_decode(src, &mut ret)
        .map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

    Ok(ret)
}