reusable-id-pool 0.1.2

A pool for RAII IDs
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented3 out of 4 items with examples
  • Size
  • Source code size: 34.09 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.46 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • davepollack

reusable-id-pool

A pool for RAII IDs.

This crate provides two structs, ReusableIdPool and ReusableIdPoolManual.

Example

use reusable_id_pool::ReusableIdPool;

let reusable_id_pool = ReusableIdPool::new();
let id = reusable_id_pool.allocate();

// Do something with the `id`, like move it into a struct. It will be returned
// to the pool when it is dropped.

ReusableIdPool

A std-only struct that hands out ArcIds, which are opaque to the user.

To assign an ID to multiple things, use ArcId::clone(&id) (uses Arc::clone under the hood) to get further instances of the ID. They compare (PartialEq) as equal.

An ID is released by dropping — when all its ArcIds are dropped. ArcId drop is constant time (decrementing a reference count, or appending to a free list for the final one).

ReusableIdPoolManual

A struct that hands out u64 IDs. This should be used instead of ReusableIdPool when the ID needs to be serialised, for example over a binary ABI, as nushift-core needs to do. The IDs must be manually returned to the pool.

#![no_std] is supported for ReusableIdPoolManual (set default-features = false if this is required), but alloc is required.

Time complexity

ReusableIdPool (std-only):

Allocate: O(1)
Release: O(1)

ReusableIdPoolManual (std):

Allocate: O(1)
Release: O(1)

ReusableIdPoolManual (#![no_std]):

Allocate: O(log n)
Release: O(log n)

The id-pool crate has more functionality than ReusableIdPoolManual, is always #![no_std], and has O(1) allocate and O(log n) release, so it probably should be used instead of ReusableIdPoolManual for this case.