@livingcoder@universeodon.com avatar

livingcoder

@livingcoder@universeodon.com

Software engineer obsessed with everything to do with software development and system design. Expect toots linking to my latest Github repo every couple weeks or so.
I also dabble in game development using Bevy (mostly).

This profile is from a federated server and may be incomplete. For a complete list of posts, browse on the original instance.

became_fish , to random
@became_fish@jorts.horse avatar

is there a way out of this pattern in :

let val = some_function();  
if val.is_none() {  
 return Ok(...);  
}  
let val = val.unwrap();  

that doesn't involve a bunch of nested match statements?

livingcoder ,
@livingcoder@universeodon.com avatar

@became_fish I'm generally okay with this pattern, but I change it up slightly to assignments from match or blocks:

From match:

let value = match some_function() {  
 Some(value) => value,  
 None => return Ok(...),  
};  

From block:

let value = {  
 let value = some_function();  
 if value.is_none() {  
 return Ok(...);  
 }  
 value.unwrap()  
};  
livingcoder ,
@livingcoder@universeodon.com avatar

@became_fish Yeah, I find it quite helpful to separate parsing logic out from the root of the function to keep the variable names clean in the root. I end up creating steps as blocks.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • test
  • worldmews
  • mews
  • All magazines