use std::fmt::Display;
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::ToTokens;
#[derive(Debug)]
pub struct CompileError {
inner: syn::Error,
}
impl From<syn::Error> for CompileError {
fn from(inner: syn::Error) -> Self {
Self { inner }
}
}
impl From<CompileError> for TokenStream {
fn from(error: CompileError) -> Self {
error.inner.into_compile_error().into()
}
}
impl CompileError {
pub fn new(span: Span, message: impl Display) -> Self {
Self {
inner: syn::Error::new(span, message),
}
}
pub fn new_spanned(tokens: impl ToTokens, message: impl Display) -> Self {
Self {
inner: syn::Error::new_spanned(tokens, message),
}
}
}