zng_ext_hot_reload_proc_macros/
util.rsuse proc_macro2::{Span, TokenStream};
use quote::{quote_spanned, ToTokens};
macro_rules! ident_spanned {
($span:expr=> $($format_name:tt)+) => {
proc_macro2::Ident::new(&format!($($format_name)+), $span)
};
}
macro_rules! ident {
($($tt:tt)*) => {
ident_spanned!(proc_macro2::Span::call_site()=> $($tt)*)
};
}
#[derive(Default)]
pub struct Errors {
tokens: TokenStream,
}
impl Errors {
pub fn push(&mut self, error: impl ToString, span: Span) {
let error = error.to_string();
self.tokens.extend(quote_spanned! {span=>
compile_error!{#error}
})
}
pub fn push_syn(&mut self, error: syn::Error) {
for error in error {
let span = error.span();
self.push(error, span);
}
}
pub fn is_empty(&self) -> bool {
self.tokens.is_empty()
}
}
impl ToTokens for Errors {
fn to_tokens(&self, tokens: &mut TokenStream) {
tokens.extend(self.tokens.clone())
}
fn to_token_stream(&self) -> TokenStream {
self.tokens.clone()
}
fn into_token_stream(self) -> TokenStream {
self.tokens
}
}