| Crates.io | skipcode |
| lib.rs | skipcode |
| version | 0.1.1 |
| created_at | 2026-01-20 18:32:47.820596+00 |
| updated_at | 2026-01-22 13:16:10.079216+00 |
| description | A Rust macro library enabling compile-time skipping of statements/blocks |
| homepage | |
| repository | https://github.com/RustFactory/skipcode |
| max_upload_size | |
| id | 2057172 |
| size | 9,906 |
A lightweight Rust macro library for conditionally skipping code at compile time, compatible with both debug and release builds.
SkipCode provides compile-time conditional compilation macros that work seamlessly across different build configurations. Unlike traditional #[cfg] attributes, these macros evaluate conditions at compile time while maintaining full type checking and syntax validation.
const blocksAdd to your Cargo.toml:
[dependencies]
skipcode = "0.1"
skip!Completely skips code blocks or statements at compile time.
use skipcode::skip;
let mut x = 0;
// Block form - completely skipped
skip! {
x = 10;
println!("This won't execute");
}
assert_eq!(x, 0);
// Single statement form
skip!(x = 20);
assert_eq!(x, 0);
// Empty block
skip! {};
// Invalid: empty input causes compile error
// skip!();
skip_if!Conditionally skips code based on a compile-time boolean expression.
use skipcode::skip_if;
let mut x = 0;
// Skip when condition is true
skip_if!(true, {
x = 30;
println!("Skipped");
});
assert_eq!(x, 0);
// Execute when condition is false
skip_if!(false, x = 40);
assert_eq!(x, 40);
// With configuration flags
skip_if!(cfg!(debug_assertions), {
println!("Debug-only code");
});
// Complex const expressions
const DEBUG: bool = true;
skip_if!(!DEBUG, x = 50);
// Empty block allowed
skip_if!(true, {});
skip_if!(cfg!(debug_assertions), {
// Expensive validation only in debug builds
validate_invariants();
log_debug_info();
});
const ENABLE_EXPERIMENTAL: bool = false;
skip_if!(ENABLE_EXPERIMENTAL, {
use_new_algorithm();
});
#[cfg(target_os = "windows")]
const IS_WINDOWS: bool = true;
#[cfg(not(target_os = "windows"))]
const IS_WINDOWS: bool = false;
skip_if!(IS_WINDOWS, {
windows_specific_setup();
});
#[test]
fn test_optional_feature() {
skip_if!(!ENABLE_FEATURE_X, {
// Tests that only run when feature is enabled
assert!(feature_x_works());
});
}
The macros use Rust's const blocks to evaluate conditions at compile time. When a condition is true:
skip!: The code is replaced with #[allow(unused)] ()skip_if!: The code branch is replaced with an empty expressionThis ensures that:
The macros provide helpful compile-time errors:
skip_if!(true,); // Error: skip_if!(): missing code after comma
skip_if!(); // Error: skip_if!(): invalid empty input
skip_if!(true, ()); // Error: skip_if!(): empty statement
The library includes comprehensive tests:
cargo test
Tests verify that:
const expressions)#[cfg] instead)Zero runtime overhead. All skipping happens during compilation, resulting in the same binary as if the code was never written.
This crate is #![no_std] compatible and contains no unsafe code.
Licensed under either of:
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate shall be dual-licensed as above, without any additional terms or conditions.
const block usage)cfg-if: Traditional cfg-based conditional compilationconst_format: Compile-time string formattingSee the examples/ directory for complete working examples:
cargo run --example development
cargo run --example features