bitbox_api/
util.rs

1pub fn remove_leading_zeroes(list: &[u8]) -> Vec<u8> {
2    if let Some(first_non_zero) = list.iter().position(|&x| x != 0) {
3        list[first_non_zero..].to_vec()
4    } else {
5        Vec::new()
6    }
7}
8
9#[cfg(feature = "multithreaded")]
10pub trait Threading: Sync + Send {}
11
12#[cfg(not(feature = "multithreaded"))]
13pub trait Threading {}
14
15#[cfg(test)]
16mod tests {
17    use super::*;
18    #[test]
19    fn test_remove_leading_zeroes() {
20        // Test with leading zeroes
21        let data = &[0, 0, 0, 1, 2, 3, 0, 4];
22        let result = remove_leading_zeroes(data);
23        assert_eq!(result, vec![1, 2, 3, 0, 4]);
24
25        // Test with no leading zeroes
26        let data = &[1, 0, 0, 1, 2, 3, 0, 4];
27        let result = remove_leading_zeroes(data);
28        assert_eq!(result, vec![1, 0, 0, 1, 2, 3, 0, 4]);
29
30        // Test with all zeroes
31        let data = &[0, 0, 0, 0, 0];
32        let result = remove_leading_zeroes(data);
33        assert_eq!(result, Vec::<u8>::new());
34
35        // Test with an empty list
36        let data = &[];
37        let result = remove_leading_zeroes(data);
38        assert_eq!(result, Vec::<u8>::new());
39    }
40}