I have a rust project which multiple people work on. There are certain problematic functions defined by external crates we use, that is the source of a lot of confusion and errors. I want to totally deny/ban the use of these functions crate-wide at compile time. Is there any way to do this?
You can use external functions that are written in any language that supports dynamic libraries. Before you can use an external function in a script, you must declare it as one of two types: These are available anywhere in the application. These are defined for a particular type of window, menu, user object, or user-defined function.
You can declare two types of external functions: Global external functions, which are available anywhere in the application Local external functions, which are defined for a particular type of window, menu, or user object These functions are part of the object's definition and can always be used in scripts for the object itself.
Before an external function can be called the first time, an administrator must do some configuration work. This work requires knowledge of the cloud platform (e.g. AWS or Microsoft Azure), especially about security.
External functions can raise additional security issues. For example, if you call a third party’s function, that party could keep copies of the data passed to the function.
You can use the disallowed_method
Clippy lint to accomplish this. (There's also disallowed_type
for types.)
For example, to disallow Box::new
:
#![deny(clippy::disallowed_method)]
fn main() {
let my_box = Box::new(123);
}
Add this to clippy.toml
in the workspace root:
disallowed-methods = [
# fully qualified function/method name:
"std::boxed::Box::new",
]
When you then run cargo clippy
, you will get an error about the usage of the disallowed function:
error: use of a disallowed method `alloc::boxed::Box::new`
--> src/main.rs:4:16
|
4 | let my_box = Box::new(123);
| ^^^^^^^^^^^^^
|
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With