launchkey_sdk/midi/
to_hex.rs

1use wmidi::U7;
2
3/// Trait for converting byte slices into formatted hexadecimal strings.
4pub trait ToHexString {
5    /// Converts to uppercase space-separated hex string (e.g., "F0 7E 00").
6    fn to_hex_string(&self) -> String;
7}
8
9impl ToHexString for &[U7] {
10    fn to_hex_string(&self) -> String {
11        self.iter()
12            .map(|byte| format!("{:02X}", u8::from(*byte))) // Convert U7 to u8 and format as hex
13            .collect::<Vec<String>>()
14            .join(" ")
15    }
16}
17
18impl ToHexString for &[u8] {
19    fn to_hex_string(&self) -> String {
20        self.iter()
21            .map(|byte| format!("{:02X}", byte))
22            .collect::<Vec<_>>()
23            .join(" ")
24    }
25}
26
27impl ToHexString for Vec<u8> {
28    fn to_hex_string(&self) -> String {
29        self.as_slice().to_hex_string()
30    }
31}