1 个稳定版本
1.69.420 | 2021年6月23日 |
---|
#9 在 #文章
9KB
超级快速转换
是 超级安全转换 的邪恶精神继承者
这是什么?
超级快速转换 (TST) 是一个提供小而高效的、安全的 std::mem::transmute
版本的库。TST 旨在为
超级安全转换
用户寻找 Windows 兼容替代品。- 在
#![forbid(unsafe_code)]
代码库中工作的程序员,他们不喜欢他们的同事。 - 编写 C、C++ 和 Go 的作者,想要写文章抨击 Rust 并非真正的内存安全。
- IOCCC 获胜者,对 Rust 有兴趣
TST 的优势
- 无不安全代码
- 无对 /proc/self/mem 的文件访问
- 纯 Rust 实现
- 无麸质,纯素食
- 无依赖
- 如果我知道如何使用
doc_include
,则会在稳定版上编译 - 在 Windows、Linux 和部分三星四门智能冰箱上可用
- 评级 R,包含暴力和语言
- 可能兼容
no_std
对于特殊用途案例(例如 FFI(仅限 RIIR(lol))),或者如果您只是想揭开面纱,请参阅 safe!
。
机器人证词
证明没有不安全
$ grep unsafe
src/lib.rs
1:#![forbid(unsafe_code)]
safe/src/lib.rs
1:#![forbid(unsafe_code)]
$ cargo geiger
Compiling safe v0.1.0 (/Users/jschmidt/totally-speedy-transmute/safe)
Checking totally-speedy-transmute v0.1.0 (/Users/jschmidt/totally-speedy-transmute)
Finished dev [unoptimized + debuginfo] target(s) in 1.36s
Scanning done
Metric output format: x/y
x = unsafe code used by the build
y = total unsafe code found in the crate
Symbols:
🔒 = No `unsafe` usage found, declares #![forbid(unsafe_code)]
❓ = No `unsafe` usage found, missing #![forbid(unsafe_code)]
☢️ = `unsafe` usage found
Functions Expressions Impls Traits Methods Dependency
0/0 0/0 0/0 0/0 0/0 🔒 totally-speedy-transmute 0.1.0
0/0 0/0 0/0 0/0 0/0 🔒 └── safe 0.1.0
0/0 0/0 0/0 0/0 0/0
$ cargo t
Compiling totally-speedy-transmute v0.1.0 (/Users/jschmidt/totally-speedy-transmute)
Finished test [unoptimized + debuginfo] target(s) in 0.26s
Running unittests (target/debug/deps/totally_speedy_transmute-c545620424772de5)
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running tests/wat.rs (target/debug/deps/wat-527d75fb46642aee)
running 5 tests
test leek ... ok
test fast_vec ... ok
test oops_all_mutable ... ok
test safe ... ok
test transmute_u8 ... ok
test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Doc-tests totally-speedy-transmute
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
$ cargo t --release
Compiling totally-speedy-transmute v0.1.0 (/Users/jschmidt/totally-speedy-transmute)
Finished release [optimized] target(s) in 0.28s
Running unittests (target/release/deps/totally_speedy_transmute-5a097808724739b1)
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running tests/wat.rs (target/release/deps/wat-20a81a817034b78e)
running 5 tests
test leek ... ok
test fast_vec ... ok
test transmute_u8 ... ok
test safe ... ok
test oops_all_mutable ... ok
test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Doc-tests totally-speedy-transmute
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
$ pushd ~/cargo-osha/
$ cargo run -- ~/totally-speedy-transmute/**/*.rs
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target/debug/cargo-osha /Users/jschmidt/totally-speedy-transmute/safe/src/lib.rs /Users/jschmidt/totally-speedy-transmute/src/lib.rs /Users/jschmidt/totally-speedy-transmute/tests/wat.rs`
Processing file /Users/jschmidt/totally-speedy-transmute/safe/src/lib.rs
Processing file /Users/jschmidt/totally-speedy-transmute/src/lib.rs
Processing file /Users/jschmidt/totally-speedy-transmute/tests/wat.rs
Unsafe functions: 0/10
Unsafe expressions: 0/42
Unsafe traits: 0/0
Unsafe methods: 0/0
Unsafe impls: 0/0
$ poopd
fish: Unknown command: poopd
$ popd