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
33
34
pub fn unwrap_or_empty_str(opt_str: &Option<String>) -> &str {
match opt_str {
Some(desc) => desc,
None => "",
}
}
pub fn get_description(opt_str: &Option<String>) -> String {
let desc: &str = unwrap_or_empty_str(opt_str);
let words: Vec<&str> = desc.split_whitespace().collect();
words.join(" ")
}
pub fn format_address(hex_address: u64) -> String {
let addr = format! {"{hex_address:x}"};
let addr = addr.to_uppercase();
format!("0x{addr}")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn correctly_format_address() {
let addr: u32 = 0xde4dBeeF;
let formatted_addr = format_address(addr as u64);
assert_eq!(formatted_addr, "0xDE4DBEEF");
}
}