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.3"
= "0.3"
Demo
pub
How does mut_set work
The macro will implement all stuffs in tests/src/basic_expand.rs.
Take Xxx as an example:
- Create two struct
ImmutIdXxx, andXxxId. WhereImmutIdXxxis 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,ImmutIdXxx, andXxxId. impl mut_set::Item for Xxx<ImmutIdItem = ImmutIdXxx>MutSet<T: Item> = HashMap<u64, T::ImmutIdItem>, where theu64is the hash value.- Wrap the iteration function
iter(&self) -> Iter<&Xxx>into_iter(self) -> Iter<Xxx>iter_mut(&mut self) -> Iter<&mut ImmutIdXxx>
Other features
-
If you want to add some
derive/proc_macrotoImmutIdXxx/XxxId. You can add arguments tomut_set_derive::item, to specify whichderiveshould add toImmutIdXxx/XxxId, and the filter for fileds attribute. e.g.,will impl
Here
some_attris not inattr_filter(), so it will be removed. See more at tests/src/derive.rs and tests/src/derive_expand.rs.