Skip to content

Commit

Permalink
fix: subclause_and_not!
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Oct 14, 2024
1 parent 6a5f407 commit 8f65b88
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

- [Changelog](#changelog)
- [2.0.2](#202)
- [2.0.1](#201)
- [2.0.0](#200)
- [1.9.2](#192)
Expand Down Expand Up @@ -37,6 +38,12 @@

---

## 2.0.2

Released on 14/10/2024

- Added `subclause_and_not!`

## 2.0.1

Released on 13/10/2024
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tuirealm"
version = "2.0.1"
version = "2.0.2"
authors = ["Christian Visintin"]
edition = "2021"
categories = ["command-line-utilities"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</p>

<p align="center">Developed by <a href="https://veeso.github.io/" target="_blank">@veeso</a></p>
<p align="center">Current version: 2.0.1 (13/10/2024)</p>
<p align="center">Current version: 2.0.2 (14/10/2024)</p>

<p align="center">
<a href="https://opensource.org/licenses/MIT"
Expand Down
52 changes: 52 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,58 @@ macro_rules! subclause_and {
};
}

/// A macro to generate a chain of [`crate::SubClause::And`] from a list of
/// Ids with the case [`crate::SubClause::Not`] containing [`crate::SubClause::IsMounted`] for every id.
///
/// Why is this useful?
/// Well, it happens quite often at least in my application to require a subclause for a "Global Listener" item
/// to have no "Popup" mounted in the application.
///
/// ### example
///
/// ```rust
/// use tuirealm::{SubClause, subclause_and_not};
///
/// #[derive(Debug, Eq, PartialEq, Clone, Hash)]
/// pub enum Id {
/// InputBar,
/// InputFoo,
/// InputOmar,
/// }
///
/// let sub_clause = subclause_and_not!(
/// Id::InputBar,
/// Id::InputFoo,
/// Id::InputOmar
/// );
///
/// assert_eq!(
/// sub_clause,
/// SubClause::And(
/// Box::new(SubClause::Not(Box::new(SubClause::IsMounted(Id::InputBar)))),
/// Box::new(SubClause::And(
/// Box::new(SubClause::Not(Box::new(SubClause::IsMounted(Id::InputFoo)))),
/// Box::new(SubClause::Not(Box::new(SubClause::IsMounted(
/// Id::InputOmar
/// ))))
/// ))
/// )
/// );
/// ```
///
#[macro_export]
macro_rules! subclause_and_not {
($id:expr) => {
SubClause::not(SubClause::IsMounted($id))
};
($id:expr, $($rest:expr),+) => {
SubClause::and(
SubClause::not(SubClause::IsMounted($id)),
subclause_and_not!($($rest),+)
)
};
}

/// A macro to generate a chain of [`crate::SubClause::Or`] from a list of
/// Ids with the case [`crate::SubClause::IsMounted`] for every id.
///
Expand Down

0 comments on commit 8f65b88

Please sign in to comment.