Skip to content

Commit 5f5535c

Browse files
committed
Use safe transmute by default
Using the zerocopy crate, we can port all header conversions from pointer cast to safe transmutes. After this change, the code in `header.rs` does not use `unsafe` anymore when the `zerocopy` feature is activated. Since this adds a derive crate without feature addition as dependency, zerocopy is an optional (but on-by-default) dependency.
1 parent 6cd40fe commit 5f5535c

4 files changed

Lines changed: 257 additions & 34 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
- run: cargo hack check --all --ignore-private --each-feature --no-dev-deps
3535
- run: cargo check --all --all-targets --all-features
3636
- run: cargo test
37+
# Test without zerocopy
38+
- run: cargo test --no-default-features
3739
- run: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
3840

3941
msrv:

Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ portable-atomic = "1"
2929
rustc-hash = "2.1.0"
3030
tokio = { version = "1", features = ["fs", "io-util", "rt"] }
3131
tokio-stream = "0.1"
32+
zerocopy = { version = "0.8.23", features = ["derive"], optional = true }
3233

3334
[dev-dependencies]
3435
tempfile = "3"
@@ -40,7 +41,9 @@ rustix = { version = "0.38", features = ["fs"] }
4041
xattr = { version = "1.0", optional = true }
4142

4243
[features]
43-
default = ["xattr"]
44+
default = ["xattr", "zerocopy"]
45+
# Use safe transmute for headers (otherwise, unsafe pointer casts are used)
46+
zerocopy = ["dep:zerocopy"]
4447

4548
[lib]
4649
name = "tokio_tar"

0 commit comments

Comments
 (0)