#times

nightly no-std flatten_objects

A container that stores numbered objects. Each object can be assigned with a unique ID.

1 unstable release

0.1.0 Jul 11, 2024

#1165 in Data structures

Download history 124/week @ 2024-07-10 285/week @ 2024-07-17 417/week @ 2024-07-24 447/week @ 2024-07-31 156/week @ 2024-08-07 162/week @ 2024-08-14 214/week @ 2024-08-21 136/week @ 2024-08-28 322/week @ 2024-09-04 242/week @ 2024-09-11 354/week @ 2024-09-18 261/week @ 2024-09-25 137/week @ 2024-10-02 554/week @ 2024-10-09

1,331 downloads per month

GPL-3.0-or-later OR Apache-2…

8KB
77 lines

flatten_objects

Crates.io

FlattenObjects is a container that stores numbered objects.

Objects can be added to the FlattenObjects, a unique ID will be assigned to the object. The ID can be used to retrieve the object later.

Example

use flatten_objects::FlattenObjects;

let mut objects = FlattenObjects::<u32, 20>::new();

// Add `23` 10 times and assign them IDs from 0 to 9.
for i in 0..=9 {
    objects.add_at(i, 23).unwrap();
    assert!(objects.is_assigned(i));
}

// Remove the object with ID 6.
assert_eq!(objects.remove(6), Some(23));
assert!(!objects.is_assigned(6));

// Add `42` (the ID 6 is available now).
let id = objects.add(42).unwrap();
assert_eq!(id, 6);
assert!(objects.is_assigned(id));
assert_eq!(objects.get(id), Some(&42));
assert_eq!(objects.remove(id), Some(42));
assert!(!objects.is_assigned(id));

lib.rs:

FlattenObjects is a container that stores numbered objects.

Objects can be added to the FlattenObjects, a unique ID will be assigned to the object. The ID can be used to retrieve the object later.

Example

use flatten_objects::FlattenObjects;

let mut objects = FlattenObjects::<u32, 20>::new();

// Add `23` 10 times and assign them IDs from 0 to 9.
for i in 0..=9 {
    objects.add_at(i, 23).unwrap();
    assert!(objects.is_assigned(i));
}

// Remove the object with ID 6.
assert_eq!(objects.remove(6), Some(23));
assert!(!objects.is_assigned(6));

// Add `42` (the ID 6 is available now).
let id = objects.add(42).unwrap();
assert_eq!(id, 6);
assert!(objects.is_assigned(id));
assert_eq!(objects.get(id), Some(&42));
assert_eq!(objects.remove(id), Some(42));
assert!(!objects.is_assigned(id));

Dependencies

~72KB