warcraft3-stats-observer 0.1.1

Rust bindings for the Warcraft 3 Stats Observer API memory map
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::fmt::Display;

#[repr(C)]
pub struct PaddedString<const SIZE: usize> {
    array: [u8; SIZE],
}

impl<const SIZE: usize> Display for PaddedString<SIZE> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        // Find null terminator
        let index = self
            .array
            .iter()
            .position(|&v| v == 0)
            .unwrap_or(self.array.len());
        write!(f, "{}", String::from_utf8_lossy(&self.array[..index]))
    }
}