| Crates.io | handle_rs |
| lib.rs | handle_rs |
| version | 0.1.1 |
| created_at | 2025-12-04 04:22:00.460774+00 |
| updated_at | 2025-12-04 04:40:00.472044+00 |
| description | a lib for using handle array in rust more easier |
| homepage | https://github.com/ctzcs/handle_rs |
| repository | |
| max_upload_size | |
| id | 1965828 |
| size | 12,600 |
Handle-based array with free-list and alive iteration.
0 to represent invalid/null handlealive_iter / alive_iter_mut filter out invalid entries for safe iterationuse std::fmt::{Display, Formatter};
use handle_rs::{Handle, HandleArray, IHandleArrayItem};
#[derive(Debug)]
struct Item {
pub value: f64,
pub handle: Handle,
}
impl IHandleArrayItem for Item {
fn get_handle(&self) -> Handle { self.handle }
fn set_handle(&mut self, handle: Handle) { self.handle = handle; }
}
impl Default for Item {
fn default() -> Self {
Item { value: 0.0, handle: Handle { index: 0, generation: 0 } }
}
}
impl Display for Item {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "value: {} , handle: {}", self.value, self.handle)
}
}
fn main() {
let mut ha = HandleArray::<Item>::new(1000);
let h0 = ha.add_item(Item { value: 0.1, handle: Handle::default() });
let _ = ha.add_item(Item { value: 0.2, handle: Handle::default() });
println!("{}", ha.get(h0));
for (_, item) in ha.alive_iter_mut() {
item.value += 0.1;
}
for (_, item) in ha.alive_iter() {
println!("alive {}", item);
}
ha.remove_item(h0);
for (_, item) in ha.alive_iter() {
println!("alive {}", item);
}
}