Skip to content

Commit

Permalink
Compile time error, if there are zero or one features available
Browse files Browse the repository at this point in the history
  • Loading branch information
omid committed Feb 5, 2024
1 parent 2e7149f commit 3ce7d10
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.1.0 (2024-02-05)

### Changed

- Compile time error, if there are zero or one features in `exactly_one_of!` and `none_or_one_of!` macros. They were ignored before.

## 0.0.3 (2023-11-09)

### Added

- It's the initial release! 🎉
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mutually_exclusive_features"
version = "0.0.3"
version = "0.1.0"
description = "Macros to check that only none or one of a set of features is enabled at a time, as known as mutually exclusive features"
license = "MIT OR Apache-2.0"
authors = ["Omid Rad <[email protected]>"]
Expand Down
4 changes: 1 addition & 3 deletions examples/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use mutually_exclusive_features::{exactly_one_of, none_or_one_of};
fn main() {
none_or_one_of!("a", "b", "c");
none_or_one_of!("a", "b",);
none_or_one_of!("a");
none_or_one_of!();

exactly_one_of!("a", "b", "c");
}
}
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ macro_rules! none_or_one_of {
};

// ignore cases
() => {};
(@recurs: [params: $F1:literal,]) => {};
() => {
compile_error!("It doesn't make sense to call it with no feature! Probably you can safely remove it.")
};
(@recurs: [params: $F1:literal,]) => {
compile_error!("It doesn't make sense to call it with only one feature! Probably you can safely remove it.")
};
}

/**
Expand Down

0 comments on commit 3ce7d10

Please sign in to comment.