//! returns: 0 /// Store and load one byte through a slice. fn byteItem(items: &mut [u8], index: u32, value: u8) -> u8 { set items[index] = value; return items[index]; } /// Store and load one full-width word through a slice. fn wordItem(items: &mut [u64], index: u32, value: u64) -> u64 { set items[index] = value; return items[index]; } /// An aggregate with two independently checked fields. record Pair: Copy { /// First word. first: u32, /// Second word. second: u64, } /// Store and load an aggregate through a slice. fn pairItem(items: &mut [Pair], index: u32, value: Pair) -> Pair { set items[index] = value; return items[index]; } /// Check dynamic array and slice addressing at each element boundary. @default fn main() -> u32 { let mut bytes: [u8; 5] = [0; 5]; let mut words: [u64; 5] = [0; 5]; let mut pairs: [Pair; 5] = [Pair { first: 0, second: 0 }; 5]; for index in 0..5 { set bytes[index] = index as u8; set words[index] = 0x100000000 + index as u64; set pairs[index] = Pair { first: index, second: words[index] }; } for index in 0..5 { assert bytes[index] == index as u8; assert words[index] == 0x100000000 + index as u64; assert pairs[index].first == index; assert pairs[index].second == words[index]; assert byteItem(&mut bytes[..], index, 255 - index as u8) == 255 - index as u8; assert wordItem(&mut words[..], index, 0x200000000 + index as u64) == 0x200000000 + index as u64; let value = Pair { first: index + 10, second: words[index] }; let result = pairItem(&mut pairs[..], index, value); assert result.first == value.first; assert result.second == value.second; } for index in 0..5 { assert bytes[index] == 255 - index as u8; assert words[index] == 0x200000000 + index as u64; assert pairs[index].first == index + 10; assert pairs[index].second == words[index]; } assert bytes[0] == 255; assert bytes[4] == 251; return 0; }