In other languages I would (unknowingly) be (probably) cloning person.id to the heap (as a String) when using more concise syntax like:
Ob{
id: person.map(|p| p.id) // p.id goes out of scope
}
In Rust, once leaving the scope of the map closure id is garbage, so I can't benefit from the conciseness of map with &str type and the alternative if statement is a lot of typing. Is there anyway to get the conciseness of mapwith the correct scoping of the above if statement while keeping the type of &str for efficiency?
For more specific advice, it would be useful to have a concrete example of a case where your if expression works but map does not. In general, these should be equivalent. For example, in this playground both of them work fine.