1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#![forbid(unsafe_code, missing_debug_implementations, missing_docs)]
#![cfg_attr(test, deny(warnings))]
extern crate failure;
use failure::Error;
pub fn fmt(input: &[u8]) -> Result<String, Error> {
let string: String =
input.iter().map(|byte| format!("{:02x}", byte)).collect();
if string.len() > 8 {
let (head, tail) = string.split_at(6);
let cut_off = tail.len() - 2;
let (_, tail) = tail.split_at(cut_off);
Ok(format!("{}..{}", head, tail))
} else {
Ok(string)
}
}