From 5db335b7c7038baa458eb5ec2fa72125c54bb1bd Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 28 Feb 2020 21:15:22 +0100 Subject: [PATCH] Add EMPTY_FLAGS to flags generator This seems like a useful primitive to have especially when dealing with `Rights` flags in `wasi-common` (and WASI in general). --- crates/generate/src/types/flags.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/generate/src/types/flags.rs b/crates/generate/src/types/flags.rs index 8837ceb796..67e380ff77 100644 --- a/crates/generate/src/types/flags.rs +++ b/crates/generate/src/types/flags.rs @@ -35,10 +35,11 @@ pub(super) fn define_flags(names: &Names, name: &witx::Id, f: &witx::FlagsDataty impl #ident { #(#flag_constructors);*; + pub const EMPTY_FLAGS: #ident = #ident(0 as #repr); pub const ALL_FLAGS: #ident = #ident(#all_values_token); pub fn contains(&self, other: &#ident) -> bool { - #repr::from(!*self & *other) == 0 as #repr + !*self & *other == Self::EMPTY_FLAGS } }