feophantlib/engine/io/block_layer/
resource_formatter.rs1use uuid::Uuid;
2
3const PREFIX_LEN: usize = 2;
5
6pub struct ResourceFormatter {}
7
8impl ResourceFormatter {
9 pub fn format_uuid(input: &Uuid) -> String {
10 let mut buf = [b'0'; 32];
11 input.to_simple().encode_lower(&mut buf);
12 String::from_utf8_lossy(&buf).into_owned()
13 }
14
15 pub fn get_uuid_prefix(input: &Uuid) -> String {
16 let mut buf = [b'0'; 32];
17 input.to_simple().encode_lower(&mut buf);
18 String::from_utf8_lossy(&buf[..PREFIX_LEN]).into_owned()
19 }
20}
21
22#[cfg(test)]
23mod tests {
24 use super::*;
25 use hex_literal::hex;
26
27 #[test]
28 fn test_uuid_formating() -> Result<(), Box<dyn std::error::Error>> {
29 let hex = "ee89957f3e9f482c836dda6c349ac632";
30 let test = Uuid::from_bytes(hex!("ee89957f3e9f482c836dda6c349ac632"));
31 assert_eq!(hex, ResourceFormatter::format_uuid(&test));
32
33 assert_eq!("ee", ResourceFormatter::get_uuid_prefix(&test));
34
35 Ok(())
36 }
37}