Better HN
topnewbestaskshowjobs
Log inSign up

rolandrodriguez

2 karma · joined Apr 1, 2021 (5y ago) · 1 submissions

Submissions

comment 1y ago · link · parent

I didn’t get past the first limitation before my brain started itching.

Wouldn’t the approach there be to avoid mutating the same string (and thus reborrowing Map) in the first place? I’m likely missing something from the use case but why wouldn’t this work?

    // Construct the fallback key separately
    let fallback = format!("{k}-default");

    // Use or_else() to avoid a second explicit `if map.contains_key(...)`
    map.get_mut(k)
       .or_else(|| map.get_mut(&fallback))