Joined 5 years ago
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))
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?