@bryan@toot.cafe avatar

bryan

@bryan@toot.cafe

I love sample day at the grocery store.

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?

bryan ,
@bryan@toot.cafe avatar

@became_fish

Not much better, but we use

let Some(val) = some_function() else {  
 return OK(…);  
};  

pretty regularly.

If you’re returning an Err instead of an Ok then

let val = some_function().ok_or(Error::…)?;  

works nicely.

became_fish , to random
@became_fish@jorts.horse avatar

alright, a much meatier problem i've been stumped on for an hour or two.

i've got a whole serde deserializer implemented that works for every use case but duplicate keys - which serde seems to explicitly object to.

i'm looking to map

val = 1  
val = 2  
val = 3  

into something like Values { val: vec![1, 2, 3] }.

anyone know of some combo of Deserializer, DeserializerSeed, Visitor i can use to make this happen? or do i gotta give up and make every struct just a Vec<(String, T)>

bryan ,
@bryan@toot.cafe avatar
  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • test
  • worldmews
  • mews
  • All magazines