cido-macros 0.2.0

Macros for generating code that enables easier interfacing with cido
Documentation
use crate::parse::deps::*;

pub mod cidomap;
pub mod event_handler;
pub mod orderby;
pub mod transformer;

pub fn err(span: &dyn syn::spanned::Spanned, t: impl core::fmt::Display) -> syn::Error {
  syn::Error::new(span.span(), t)
}

#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug, Default)]
#[repr(u8)]
pub enum ProcessingOrder {
  #[default]
  One = 1,
  Two = 2,
  Three = 3,
}

impl From<ProcessingOrder> for u8 {
  fn from(val: ProcessingOrder) -> Self {
    val as u8
  }
}

impl TryFrom<u8> for ProcessingOrder {
  type Error = u8;

  fn try_from(value: u8) -> Result<Self, Self::Error> {
    match value {
      1 => Ok(ProcessingOrder::One),
      2 => Ok(ProcessingOrder::Two),
      3 => Ok(ProcessingOrder::Three),
      val => Err(val),
    }
  }
}

impl deluxe::ParseMetaItem for ProcessingOrder {
  fn parse_meta_item(
    input: syn::parse::ParseStream,
    _mode: deluxe::ParseMode,
  ) -> deluxe::Result<Self> {
    let u = input.parse::<syn::LitInt>()?;
    let u = u.base10_parse::<u8>()?;
    Self::try_from(u).map_err(|_| crate::err(&u, "Invalid order"))
  }
}

macro_rules! tracing_quote {
  ($($tt:tt)*) => {{
    let ___trace = format!("{}:{}", file!(), line!());
    $crate::prelude::quote::quote!{
      const _: &str = #___trace;
      $($tt)*
    }
  }}
}

#[derive(Default, Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct CodegenWrapper<T>(pub T);

impl<T> core::ops::Deref for CodegenWrapper<T> {
  type Target = T;
  fn deref(&self) -> &Self::Target {
    &self.0
  }
}

impl<T> core::ops::DerefMut for CodegenWrapper<T> {
  fn deref_mut(&mut self) -> &mut Self::Target {
    &mut self.0
  }
}