kago-macros 0.3.0

A macros for Kago.
Documentation
use proc_macro2::TokenStream;
use quote::quote;
use syn::Ident;

pub fn impl_sign(struct_name: &Ident, is_signed: bool) -> TokenStream {
    if is_signed {
        quote! {
            impl std::ops::Neg for #struct_name {
                type Output = Self;

                fn neg(self) -> Self::Output {
                    Self::from_bits(-self.0)
                }
            }

            impl num_traits::sign::Signed for #struct_name {
                fn abs(&self) -> Self {
                    Self::from_bits(self.0.abs())
                }

                fn abs_sub(&self, other: &Self) -> Self {
                    Self::from_bits(self.0.abs_sub(&other.0))
                }

                fn signum(&self) -> Self {
                    Self::new(self.0.signum())
                }

                fn is_positive(&self) -> bool {
                    self.0.is_positive()
                }

                fn is_negative(&self) -> bool {
                    self.0.is_negative()
                }
            }
        }
    } else {
        quote! {
            impl num_traits::sign::Unsigned for #struct_name {}
        }
    }
}