4 ms·
I don't understand why go through the complication of giving this a new name (i.e. "Restructuring Pattern") where the second explanation seems more intuitive an
by juancampa 4y ago
I don't understand why go through the complication of giving this a new name (i.e. "Restructuring Pattern") where the second explanation seems more intuitive and correct.
"Restructuring Pattern" sounds like you can put back together a struct from its constituents, but that's done by normal struct instantiation.
- fkcgnad 4y agoThe author is talking about restructuring syntax in the destructing match. Rust Has this with "match" but only via a single ref. You would have to make alternative restructuring syntax to go into the match expression if you want it to work. Hypothetically: fn g(v: Option<i32>) -> Option<Option<i32>> { match v { Some(_Some(_Some(x))), None(_None) } } Any character with an underscore is a "restructuring" syntax here. Rust only does restructuring with references via the ref keyword and it only does it once per var per expression. The syntax I presented here is hypothetical of course. I would say it's more syntactic sugar as you can do the restructuring on the right side of the match expression. You can make up an entire functional language using this technique and eliminate the => and everything after it. I largely agree with you that it's not exactly necessary to do this. Arguably it makes things harder to read.