Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <casey@rodarmor.com>"]
rust-version = "1.89.0"

[features]
default = []
Expand Down
1 change: 1 addition & 0 deletions bin/demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ name = "demo"
version = "0.0.0"
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
publish = false
1 change: 1 addition & 0 deletions bin/gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "gen"
version = "0.0.0"
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
publish = false

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions bin/update-contributors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "update-contributors"
version = "0.0.0"
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
publish = false

[dependencies]
Expand Down
3 changes: 1 addition & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 7 additions & 11 deletions src/piece_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
4 changes: 2 additions & 2 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading