use proc_macro::{TokenStream, TokenTree}; use proc_macro2::Span; use quote::quote; use syn::{parse::Parser, Ident};
pub(crate) fn declare_output_enum(input: TokenStream) -> TokenStream { // passed in is: `(_ _ _)` with one `_` per branch let branches = match input.into_iter().next() {
Some(TokenTree::Group(group)) => group.stream().into_iter().count(),
_ => panic!("unexpected macro input"),
};
let variants = (0..branches)
.map(|num| Ident::new(&format!("_{}", num), Span::call_site()))
.collect::<Vec<_>>();
// Use a bitfield to track which futures completed let mask = Ident::new( if branches <= 8 { "u8"
} elseif branches <= 16 { "u16"
} elseif branches <= 32 { "u32"
} elseif branches <= 64 { "u64"
} else {
panic!("up to 64 branches supported");
},
Span::call_site(),
);
TokenStream::from(quote! { pub(super) enum Out<#(#variants ),*> { #(#variants(#variants), )* // Include a `Disabled` variant signifying that all select branches // failed to resolve.
Disabled,
}
pub(super) type Mask = #mask;
})
}
pub(crate) fn clean_pattern_macro(input: TokenStream) -> TokenStream { // If this isn't a pattern, we return the token stream as-is. The select! // macro is using it in a location requiring a pattern, so an error will be // emitted there. letmut input: syn::Pat = match syn::Pat::parse_single.parse(input.clone()) {
Ok(it) => it,
Err(_) => return input,
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.