Crates.io | abort-if |
lib.rs | abort-if |
version | 0.1.2 |
source | src |
created_at | 2022-12-28 00:14:39.380311 |
updated_at | 2022-12-28 00:39:28.486942 |
description | Very handy attribute to abort a function at compile-time if something goes wrong |
homepage | |
repository | https://github.com/blyxyas/abort-if |
max_upload_size | |
id | 746550 |
size | 7,968 |
The abort_if
procedural macro guarantees that a specific function panics if a condition is met.
Put this in your Cargo.toml
file:
[dependencies]
abort-if = "0.1.2"
You can assure that a function won't be used if feature x
is enabled
use abort_if::abort_if;
#[abort_if(feature = x)]
fn foo() {
using_that_feature();
}
fn main() {
foo();
}
This code will panic if that feature is enabled.
The default is panicking using compiler_error!
. This will output the following information:
error: Condition was met.
--> src/main.rs:5:1
|
5 | #[abort_if(feature = "x")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `abort_if` (in Nightly builds, run with -Z macro-backtrace for more info)
You can use the feature custom_abort
to write a custom abort macro. When using this feature, make sure to have a custom_abort_error!
macro with an expr
as the argument.
If you use the custom_abort
feature, you can also use the keep_going
one. This feature functions that, if your custom_abort_error
macro works as a warning instead of a hard error, the code will keep going.