diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 84fb902..f9efbd3 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -18,6 +18,21 @@ env: RUSTFLAGS: --deny warnings jobs: + msrv: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: 1.89.0 + + - uses: Swatinem/rust-cache@v2 + + - name: Check + run: cargo check --workspace + all: name: All diff --git a/Cargo.toml b/Cargo.toml index b68d7a0..bc5de0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,11 +12,13 @@ keywords = ["p2p", "sharing", "bittorrent", "torrent"] license.workspace = true readme = "README.md" repository = "https://github.com/casey/intermodal" +rust-version.workspace = true [workspace.package] edition = "2021" license = "CC0-1.0" authors = ["Casey Rodarmor "] +rust-version = "1.89.0" [features] default = [] diff --git a/bin/demo/Cargo.toml b/bin/demo/Cargo.toml index 380142d..3bb4162 100644 --- a/bin/demo/Cargo.toml +++ b/bin/demo/Cargo.toml @@ -3,4 +3,5 @@ name = "demo" version = "0.0.0" authors.workspace = true edition.workspace = true +rust-version.workspace = true publish = false diff --git a/bin/gen/Cargo.toml b/bin/gen/Cargo.toml index ac8f9de..20f4268 100644 --- a/bin/gen/Cargo.toml +++ b/bin/gen/Cargo.toml @@ -3,6 +3,7 @@ name = "gen" version = "0.0.0" authors.workspace = true edition.workspace = true +rust-version.workspace = true publish = false [dependencies] diff --git a/bin/update-contributors/Cargo.toml b/bin/update-contributors/Cargo.toml index 5ad9165..587481c 100644 --- a/bin/update-contributors/Cargo.toml +++ b/bin/update-contributors/Cargo.toml @@ -3,6 +3,7 @@ name = "update-contributors" version = "0.0.0" authors.workspace = true edition.workspace = true +rust-version.workspace = true publish = false [dependencies] diff --git a/build.rs b/build.rs index db14a8b..efc333f 100644 --- a/build.rs +++ b/build.rs @@ -8,8 +8,7 @@ fn is_inside_git_work_tree() -> bool { .arg("rev-parse") .arg("--is-inside-work-tree") .output() - .map(|output| String::from_utf8_lossy(&output.stdout).trim() == "true") - .unwrap_or(false) + .is_ok_and(|output| String::from_utf8_lossy(&output.stdout).trim() == "true") } fn error(message: String) -> io::Error { diff --git a/src/piece_list.rs b/src/piece_list.rs index 2662b02..10c77f9 100644 --- a/src/piece_list.rs +++ b/src/piece_list.rs @@ -57,23 +57,19 @@ impl<'de> Deserialize<'de> for PieceList { { let bytes = serde_bytes::ByteBuf::deserialize(deserializer)?.into_vec(); - if bytes.len() % Sha1Digest::LENGTH != 0 { + let (chunks, remainder) = bytes.as_chunks::<{ Sha1Digest::LENGTH }>(); + + if !remainder.is_empty() { return Err(D::Error::custom(format!( "buffer length {} is not a multiple of {}", bytes.len(), - sha1_smol::DIGEST_LENGTH + Sha1Digest::LENGTH, ))); } - let piece_hashes = bytes - .chunks_exact(Sha1Digest::LENGTH) - .map(|chunk| { - Sha1Digest::from_bytes( - chunk - .try_into() - .invariant_unwrap("chunks are all Sha1Digest::LENGTH"), - ) - }) + let piece_hashes = chunks + .iter() + .map(|chunk| Sha1Digest::from_bytes(*chunk)) .collect(); Ok(Self { piece_hashes }) diff --git a/src/table.rs b/src/table.rs index fe379dd..13696b6 100644 --- a/src/table.rs +++ b/src/table.rs @@ -273,14 +273,14 @@ mod tests { .write_human_readable(&mut cursor, Style::inactive()) .unwrap(); let have = String::from_utf8(cursor.into_inner()).unwrap(); - assert_eq!(have, want, "have != want:\nHAVE:\n{have}\nWANT:\n{want}",); + assert_eq!(have, want, "have != want:\nHAVE:\n{have}\nWANT:\n{want}"); } fn tab_delimited(table: &Table, want: &str) { let mut cursor = Cursor::new(Vec::new()); table.write_tab_delimited(&mut cursor).unwrap(); let have = String::from_utf8(cursor.into_inner()).unwrap(); - assert_eq!(have, want, "have != want:\nHAVE:\n{have}\nWANT:\n{want}",); + assert_eq!(have, want, "have != want:\nHAVE:\n{have}\nWANT:\n{want}"); } #[test]