Wonderful community members, I have been playing with rust macros for a week now and came with a macro that generates (or at least tries to..) python code when I expand the macro i.e in the [EXPANSION].rs file.
Here is the macro what I came up with so far
macro_rules! genpy {
(
$(
$Name: ident {
$($Field: ident),* $(,)?
}
)*
) => {
$(
class $Name():
def __init__(self, $($Field,)*):
$(
self.$Field = $Field
)*
)*
};
}
Then I call the macro in my main function like the following:
genpy!(Human { name, age sex })
If I open the [EXPANSION].rs
in vscode, I see something like this.
// Recursive expansion of genpy! macro
// ===============================================
class Human():def __init__(self, name, age, sex,):self.name = name self.age = age self.sex = sex
Is there a way, I can make it look like
class Human():
def __init__(self, name, age, sex):
self.name = name
self.age = age
self.sex = sex
PS: I am not trying to run this code using rust, but, trying to generate a piece of code that looks like Python with indents and space.
Thanks a lot again for being an awesome community