From 56a981bdd80dc1919407b07555187cba6c7554b4 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 19 Jan 2023 09:27:42 -0800 Subject: [PATCH] Add `contains` and `intersects` to the component-macro bindings for flags. (#5598) In component-macro, when expanding the bindings for flags types, add `contains` and `intersects` methods, for convenience. --- crates/component-macro/src/component.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/component-macro/src/component.rs b/crates/component-macro/src/component.rs index b87fb6cb3c..b054f993ce 100644 --- a/crates/component-macro/src/component.rs +++ b/crates/component-macro/src/component.rs @@ -1114,6 +1114,14 @@ pub fn expand_flags(flags: &Flags) -> Result { use std::ops::Not; Self::default().not() } + + pub fn contains(&self, other: Self) -> bool { + *self & other == other + } + + pub fn intersects(&self, other: Self) -> bool { + *self & other != Self::empty() + } } impl std::cmp::PartialEq for #name {