Skip to content

Commit

Permalink
Replace i32 with u32 in build.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb authored and zowens committed Feb 8, 2024
1 parent 8799754 commit 4bd4615
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
26 changes: 12 additions & 14 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
extern crate rustc_version;

use rustc_version::{version_meta, Channel};
use std::io::Write;
use std::path::Path;
use std::{io, ops};

Expand All @@ -12,7 +13,7 @@ pub const POLYNOMIAL: u32 = 0x82_F6_3B_78;
fn sw_table() -> [[u32; 256]; 8] {
let mut table: [[u32; 256]; 8] = [[0u32; 256]; 8];

for n in 0..256 {
for n in 0..256_u32 {
let mut crc = n;

for _ in 0..8 {
Expand Down Expand Up @@ -45,8 +46,8 @@ pub struct Matrix([u32; 32]);

impl Matrix {
/// Allocates space for a new matrix.
fn new() -> Self {
Matrix([0u32; 32])
const fn new() -> Self {
Self([0u32; 32])
}

/// Multiplies a matrix by itself.
Expand Down Expand Up @@ -136,10 +137,10 @@ fn hw_table(len: usize) -> [[u32; 256]; 4] {
let mut zeroes: [[u32; 256]; 4] = [[0u32; 256]; 4];
let op = create_zero_operator(len);

for n in 0..256 {
for i in 0..4 {
for n in 0..256_u32 {
for i in 0..4_u32 {
let shift = i * 8;
zeroes[i as usize][n] = op * ((n << shift) as u32);
zeroes[i as usize][n as usize] = op * (n << shift);
}
}

Expand All @@ -151,20 +152,17 @@ pub const LONG: usize = 8192;
pub const SHORT: usize = 256;

fn write_table(table: &[[u32; 256]], path: &Path) -> io::Result<()> {
use std::fs;

let mut file = {
let file = fs::File::create(path)?;
let file = std::fs::File::create(path)?;
io::BufWriter::new(file)
};

use std::io::Write;
write!(file, "[")?;

for row in table.iter() {
for row in table {
write!(file, "[")?;
for element in row.iter() {
write!(file, "{}, ", element)?;
for element in row {
write!(file, "{element}, ")?;
}
write!(file, "],")?;
}
Expand All @@ -187,7 +185,7 @@ fn write_tables() -> io::Result<()> {
fn main() {
write_tables().expect("Failed to write CRC tables");

if let Channel::Nightly = version_meta().unwrap().channel {
if version_meta().unwrap().channel == Channel::Nightly {
println!("cargo:rustc-cfg=nightly");
}
}
2 changes: 1 addition & 1 deletion src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mod tests {

#[test]
fn can_read() {
let mut reader = Crc32cReader::new(&TEST_STRING[..]);
let mut reader = Crc32cReader::new(TEST_STRING);
let mut buf = Vec::default();
let n_read = reader.read_to_end(&mut buf).unwrap();
assert_eq!(n_read, TEST_STRING.len());
Expand Down

0 comments on commit 4bd4615

Please sign in to comment.