kago-macros 0.3.0

A macros for Kago.
Documentation
use proc_macro2::TokenStream;
use quote::quote;
use syn::{Ident, LitInt, Type};

pub fn impl_bounded(struct_name: &Ident, ty: &Type, shift: &Option<LitInt>) -> TokenStream {
    if let Some(shift) = shift {
        quote! {
            impl num_traits::Bounded for #struct_name {
                fn min_value() -> Self {
                    Self::from_bits(#ty::MIN >> #shift << #shift)
                }
                fn max_value() -> Self {
                    Self::from_bits(#ty::MAX >> #shift << #shift)
                }
            }
        }
    } else {
        quote! {
            impl num_traits::Bounded for #struct_name {
                fn min_value() -> Self {
                    Self::from_bits(#ty::MIN)
                }
                fn max_value() -> Self {
                    Self::from_bits(#ty::MAX)
                }
            }
        }
    }
}