wasmtime-component-macro: struct and consts created for flags! must be pub (#5030)

* wasmtime-component-macro: struct and consts created for flags! must be pub

* addd empty and all constructors to flags
This commit is contained in:
Pat Hickey
2022-10-07 16:36:27 -07:00
committed by GitHub
parent e45577e097
commit 42d460f3a6

View File

@@ -1081,7 +1081,7 @@ fn expand_flags(flags: &Flags) -> Result<TokenStream> {
let name = format_ident!("{}", name); let name = format_ident!("{}", name);
constants.extend(quote!(const #name: Self = Self { #fields };)); constants.extend(quote!(pub const #name: Self = Self { #fields };));
} }
let generics = syn::Generics { let generics = syn::Generics {
@@ -1128,14 +1128,23 @@ fn expand_flags(flags: &Flags) -> Result<TokenStream> {
let expanded = quote! { let expanded = quote! {
#[derive(Copy, Clone, Default)] #[derive(Copy, Clone, Default)]
struct #name { #fields } pub struct #name { #fields }
impl #name { impl #name {
#constants #constants
fn as_array(&self) -> [u32; #count] { pub fn as_array(&self) -> [u32; #count] {
#as_array #as_array
} }
pub fn empty() -> Self {
Self::default()
}
pub fn all() -> Self {
use std::ops::Not;
Self::default().not()
}
} }
impl std::cmp::PartialEq for #name { impl std::cmp::PartialEq for #name {