Hi all,
I am new to Rust. Please see this C++ code.
"""----------------------------------------------------------------
#define end };
#define log(x) cout << x << endl
#define wait std::cin.get()
int main() {
log( "Trying to avoid visual clutter caused by closing curly brace") ;
string myStr = "Now, code looks cleaner..." ;
log(myStr) ;
wait ;
end
```cpp
"""----------------------------------------------------------------
How can i do this with Rust macros ?
Not sad at all. If people cannot do such things then I won't have to suffer reading code where people do it. I cannot agree that "end_main" and "end_if" are more readable than a simple "}". It's longer, it's uglier, it's redundant.
I think that if you are having difficulty telling which "}" belongs to which "fn", "if" etc then it is a sure sign that your functions are getting too long and complicated and it's time to get things organized properly.
To answer this more seriously — you can't. Rust syntax requires all parenthesis and braces to be balanced at all times. Macros are not textual find'n'replace. They work on the syntax tree, meaning they can only insert full working expressions and statements.
I prefer words over signs. Thats why i love this style. I know most programming languages uses signs over words, for example, && instead of and || instead of or. Well, this is my personal opinion.There is no issues with my functions.
No, I am happy with the current rust style. I would like to change it only if i can do it as easy as c++. Otherwise, i am not interested to make any changes.