Macro that concatenates name and type given

Hey! I want to make a macro for serde default workarounds but I am not sure what I want to do is possible with a simple declarative macro. But maybe I'm missing something


#[macro_export]
macro_rules! serde_default {
    ($kind:ty) => {
        pub const fn default_$kind<const V: $kind>() -> $kind {
            V
        }
    };
}
// usage
serde_default!(u16);

// and this should generate
pub const fn default_u16<const V: u16>() -> u16 {
    V
}

You need paste! it. Rust Playground

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.