Is there any way to get or view the the number of unsafe block in a project or in a rust library ?
Is the any Commands for this?
i feel it will be nice if crates.io show the number of unsafe block in each librrary
Is there any way to get or view the the number of unsafe block in a project or in a rust library ?
Is the any Commands for this?
i feel it will be nice if crates.io show the number of unsafe block in each librrary
There's cargo-geiger
, but in my opinion this isn't as useful as you'd think.
If you want to inspect the unsafe usage in a particular source tree, just grep for it.
If you are on a Unix system, grep -r -E "unsafe\s?\{" | wc -l
should give you a decent estimate.
You can also just piggyback on the compiler for a 100% accurate detection of unsafe blocks:
#![forbid(unsafe_code)]
at the top of lib.rs
temporarilycargo build
will now give you errors for every single use of unsafe
, including unsafe impl
s and other things which a simple grep invocation might not detect.You're probably making a dangerous assumption that absence of unsafe
means safety. There are many dangerous constructs that are technically "safe" in Rust. There are also ways of running unsafe code without the unsafe
block, e.g. via no_mangle
or linker directives.
You should check out cargo-crev — Rust/Cargo add-on // Lib.rs and cargo-audit — Rust/Cargo add-on // Lib.rs if you're worried about safety of dependencies.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.