I have several issues with this code so ignore the unsafe etc but the first is indexing the 2d array. For some reason it panics on row 5 although there are 7 rows.
[0, 0, 0, 0, 0]
[2, 0, 0, 0, 0]
[4, 0, 0, 0, 0]
[6, 0, 0, 0, 0]
thread 'main' panicked at 'index out of bounds: the len is 4 but the index is 4', src\protocol\cc_out.rs:197:26
cc_out_next_seq() is called seven times just for testing.
pub struct CCData{
// Default array contains the C0 values that define how C1-C4 are defined
cc_array : [[u8; 5];7],
// Single row of the array is returned as next in sequence
cc_el : [u8; 5],
}
// Implementation methods on CCData
impl CCData {
// Create a new instance and initialise the default arrays
pub fn new() -> CCData {
CCData {
cc_array: (
[
[ 0x00, 0x00, 0x00, 0x00, 0x00 ],
[ 0x02, 0x00, 0x00, 0x00, 0x00 ],
[ 0x04, 0x00, 0x00, 0x00, 0x00 ],
[ 0x06, 0x00, 0x00, 0x00, 0x00 ],
[ 0x08, 0x00, 0x00, 0x00, 0x00 ],
[ 0x12, 0x00, 0x00, 0x00, 0x00 ],
[ 0x14, 0x00, 0x00, 0x00, 0x00 ],
]
),
cc_el: ([ 0x00, 0x00, 0x00, 0x00, 0x00 ]),
}
}
// Return the next CC data in sequence
pub fn cc_out_next_seq(&mut self) -> [u8; 5] {
unsafe {
self.cc_el = self.cc_array[0..4][CC_IDX];
CC_IDX = CC_IDX + 1;
if CC_IDX > RR_CC {
CC_IDX = 0;
}
};
return self.cc_el;
}
}