fn table_checksum(table: &[u8]) -> u32 {
    // NOTE: use `array_chunks` or `as_chunks` once stable and remove `try_into` below
    let iter = table.chunks_exact(4);
    let remainder = iter.remainder();

    let sum = iter.fold(0u32, |a, x| {
        // slice `x` is convertible to `&[u8, 4]` because of `chunks_exact(4)`
        a.wrapping_add(u32::from_be_bytes(x.try_into().unwrap()))
    });

    // add zero-padding to remainder
    let mut rest = [0; 4];

    for (offset, byte) in remainder.iter().enumerate() {
        rest[offset] = *byte;
    }

    sum + u32::from_be_bytes(rest)
}
/// Returns the checksum of a table.
Returns the checksum of a table.
Returns the checksum of a table .
fn table_checksum(table: &[u8]) -> u32 {
    // NOTE: use `array_chunks` or `as_chunks` once stable and remove `try_into` below
    let iter = table.chunks_exact(4);
    let remainder = iter.remainder();
    let sum = iter.fold(0u32, |a, x| {
        // slice `x` is convertible to `&[u8, 4]` because of `chunks_exact(4)`
        a.wrapping_add(u32::from_be_bytes(x.try_into().unwrap()))
    });
    // add zero-padding to remainder
    let mut rest = [0; 4];
    for (offset, byte) in remainder.iter().enumerate() {
        rest[offset] = *byte;
    }
    sum + u32::from_be_bytes(rest)
}
fn table_checksum ( table : & [ u8 ] ) -> u32 { // NOTE: use `array_chunks` or `as_chunks` once stable and remove `try_into` below let iter = table . chunks_exact ( 4 ) ; let remainder = iter . remainder ( ) ; let sum = iter . fold ( 0u32 , | a , x | { // slice `x` is convertible to `&[u8, 4]` because of `chunks_exact(4)` a . wrapping_add ( u32 :: from_be_bytes ( x . try_into ( ) . unwrap ( ) ) ) } ) ; // add zero-padding to remainder let mut rest = [ 0 ; 4 ] ; for ( offset , byte ) in remainder . iter ( ) . enumerate ( ) { rest [ offset ] = * byte ; } sum + u32 :: from_be_bytes ( rest ) }
Returns the checksum of a table.
Returns the checksum of a table .
table
&[u8]
table
&[u8]