mut_set
Use the idea of readonly to implement HashSet with iter_mut.
Add crates by following command
cargo add mut_set mut_set_derive
or add it into Cargo.toml
[]
= "0.2"
= "0.2"
Demo
pub
How does mut_set implement
The macro will implement all stuffs in tests/src/prototype.rs.
Take xxx as an example:
- Create two struct
xxxImmutId, andxxxId. WherexxxImmutIdis same toxxxwith private id fields, andxxxIdonly contains id fields. - Do rearrangement so that all id fields are located at beginning of the structure. By the help of
#[repr(C)], we can use raw pointer operations to (zero-cost?) convertxxx,xxxImmutId, andxxxId. impl mut_set::Item for xxx<ItemImmutId = xxxImmutId>MutSet<T: Item> = HashMap<u64, T::ItemImmutId>, where theu64is the hash value.- Wrap the iteration function
iter(&self) -> Iter<&xxx>into_iter(self) -> Iter<xxx>iter_mut(&mut self) -> Iter<&mut xxxImmutId>