#safe #transmute #write #safety #macro #fun #user

friendly_safety_buddy

一个用于编写安全代码的有趣宏

1 个不稳定版本

0.1.0 2021 年 6 月 23 日

#2319Rust 模式


totally-speedy-transmute 中使用

MIT 许可证

2KB

超级快速转换

超级安全转换 的邪恶精神继承者

这是什么?

超级快速转换(TST)是一个库,提供了一种小巧、性能导向、安全版本的 std::mem::transmute。TST 旨在为

  • Totally Safe Transmute 用户提供一个 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

无运行时依赖