I've got a macro that I've written that is doing everything I'd like except I'd like to make it work without requiring a type parameter. In this future case I plan on using a procedural macro to define a struct that takes no type parameters but mirrors the struct passed to the procedural macro. I'd like to avoid the type parameter because my understanding is that it will limit de-/serializability.
#[macro_export]
macro_rules! partial {
( $type:ty { $( $prop:ident: $value:expr ),* } ) => {
{
type T = Partial<$type>;
T
{
$(
$prop: PartialProperty::UserDefinedValue($value),
)*
..T::default()
}
}
};
}
I know these macros are operating with ASTs and so I can't simply do something like this, but hopefully it gets the idea across of what I am looking to do.
#[macro_export]
macro_rules! partial {
( $type:ty { $( $prop:ident: $value:expr ),* } ) => {
{
Partial$type
{
$(
$prop: PartialProperty::UserDefinedValue($value),
)*
..Partial$type::default()
}
}
};
}
Where the idea is that the type can be derived by a concatenation of 'Partial' + ${original_type_name_here}
.
Is there a way I would be able to determine what struct I should be attempting to instantiate based off of the struct type passed in?