Create view of map by transforming values, à la Guava Maps.transformValues

In Java, the Guava Maps.transformValues(Map<K,V1> fromMap, Function<V1,V2> function) creates a new view of the map. javadoc

Is there a similar function in Rust that returns a view of a map without allocating a new map?

My use case is I have a HashMap<GuardId, [u8; 60]> and I want to transform it into HashMap<GuardId, u8>.

2 Likes

No, you will either have to roll out your own view struct for this or allocate a new HashMap

1 Like