Nibbles of Rust – Restructuring Patterns
catmonad.xyz
Nibbles of Rust – Restructuring Patterns
1–10 of 31 posts
Re: Nibbles of Rust – Restructuring Patterns
#2Re: Nibbles of Rust – Restructuring Patterns
#3"Restructuring Pattern" sounds like you can put back together a struct from its constituents, but that's done by normal struct instantiation.
Re: Nibbles of Rust – Restructuring Patterns
#4Re: Nibbles of Rust – Restructuring Patterns
#5Or am I missing something?
Re: Nibbles of Rust – Restructuring Patterns
#6I honestly am a bit frustrated with Rusts pattern matching ergonomics, cuz it ends up requiring me to introduce indentation in places where I don’t want it, mainly to futz around with unwrapping structures or the like.
Lots of helper methods exist on standard library enumerations but I really want there to be some nice built in macros to just give me the innards when I need it, and have a control flow block for when I _cant_ pattern match (and thus want to do an early return or blow up). Maybe this already exists!
Too much indentation makes languages unfun (see every lisp struggle with this with name binding)
Re: Nibbles of Rust – Restructuring Patterns
#7Nice tip. I honestly am a bit frustrated with Rusts pattern matching ergonomics, cuz it ends up requiring me to introduce indentation in places where I don’t want it, mainly to futz around with unwrapping structures or the like. Lots of helper methods exist on standard library enumerations but I really want there to be some nice built in macros to just give me the innards when I need it, and have a control flow block…
Re: Nibbles of Rust – Restructuring Patterns
#8Nice tip. I honestly am a bit frustrated with Rusts pattern matching ergonomics, cuz it ends up requiring me to introduce indentation in places where I don’t want it, mainly to futz around with unwrapping structures or the like. Lots of helper methods exist on standard library enumerations but I really want there to be some nice built in macros to just give me the innards when I need it, and have a control flow block…
Re: Nibbles of Rust – Restructuring Patterns
#9Nice tip. I honestly am a bit frustrated with Rusts pattern matching ergonomics, cuz it ends up requiring me to introduce indentation in places where I don’t want it, mainly to futz around with unwrapping structures or the like. Lots of helper methods exist on standard library enumerations but I really want there to be some nice built in macros to just give me the innards when I need it, and have a control flow block…
You mean like ‘matches!’? https://doc.rust-lang.org/std/macro.matches.html
let MyEnum(foo, bar, baz) = input but otherwise { do some stuff return some value }
Point being I don’t have to check for MyEnum-ness twice (like with matches! + if let) and the indented code is for the exception (no match) not the norm.
Tho I … guess !matches(MyEnum{ .. }) is not the worst… but it’s annoying to have this pattern all over my code instead of as some encoded concept we all use
Re: Nibbles of Rust – Restructuring Patterns
#10Earlier quoted context omitted.
You mean like ‘matches!’? https://doc.rust-lang.org/std/macro.matches.html
What I want is.. let MyEnum(foo, bar, baz) = input but otherwise { do some stuff return some value } Point being I don’t have to check for MyEnum-ness twice (like with matches! + if let) and the indented code is for the exception (no match) not the norm. Tho I … guess !matches(MyEnum{ .. }) is not the worst… but it’s annoying to have this pattern all over my code instead of as some encoded concept we all use
let Some(y) = x else { do_stuff(); return };
I think it was a fairly recent addition to Rust.