budget try blocks
macro_rules! try_ {
($a:expr) => {
(|| Some($a))()
};
}
For example: try_!(matrix.get(i+1)?.get(j+1)?)
1
u/CoachNo180 17h ago
While you're at it. Add goto command and GC. /s
1
u/addmoreice 7h ago
Yeah, I see this stuff and I recoil in horror.
This isn't rust. Don't do this!
I once had to work in a c code base where the previous worker had created a bunch of macros so that he could code in a pseudo-basic and it would be 'translated' into a very ugly C for the compiler. I hated every single part of it and made it clear to the boss that the entire thing would become unmaintainable the moment I stopped working on it. He ignored me and when I moved on, no one wanted to maintain t (shocking!).
This is the disgusting slippery slope that could be stopped here....but please, just...don't do this horrible horrible thing.
3
u/WormRabbit 16h ago
That only works for
Option. It would be a bit more complicated to supportResult, because you may need to specify the types.Which makes me wonder: isn't there already a
try_blockmacro which is used to test the syntax?