Comments (1)
Being able to actually mutate the values of the map would make the data structure non-persistent (i.e. previous versions of the data structure would be changed).
The recommended way to do this is by making an entirely new map:
let map: HashTrieMap<&str, i32> =
HashTrieMap::new()
.insert("a", 0)
.insert("b", 1);
let map_updated: HashTrieMap<&str, i32> = map.iter().map(|(&k, &v)| {
(k, v + 1)
}).collect();
However, this would require you to clone/copy the keys/values.
There is, of course, a way to cheat with interior mutability. You can have the values wrapped around a Cell
/RefCell
/Mutex
:
let map =
HashTrieMap::new()
.insert("a", RefCell::new(0))
.insert("b", RefCell::new(1));
for (_, v) in map.iter() {
let mut mut_v = v.borrow_mut();
*mut_v = *mut_v + 1;
}
Keep in mind that previous versions of the map will also change.
from rpds.
Related Issues (20)
- Implement optimizations in Vector
- Debug shows internal data in all data structures and iterators
- Avoiding stackoverflow when dropping large List HOT 3
- Add feature to provide Trace and Finalize impls for https://github.com/Manishearth/rust-gc
- HAMP vs CHAMP
- Implement .range_index() for RedBlackTreeMap/RedBlackTreeSet HOT 1
- Memory Usage for Debugging HOT 4
- Is this stable for handling large scale data (> 10^8) HOT 1
- Finger Trees HOT 1
- faster slicing for vectors? HOT 3
- `RedBlackTreeSet`'s docs mention non-existent `get` operation HOT 2
- Consider re-exporting archery items
- Consider providing a .pop_with_value() helper on Stack and List
- Support custom allocator HOT 1
- Serializing multiple instances efficiently HOT 1
- extract variants of remove on HashTrieMap and RedBlackTreeMap
- Add a "feature" to remove _mut methods HOT 4
- Opening doc. HOT 1
- Non-empty containers HOT 1
- sparse_array_usize test failures on i686 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rpds.