flatten_objects

Crates.ioflatten_objects
lib.rsflatten_objects
version
sourcesrc
created_at2024-07-11 07:33:23.353786
updated_at2024-12-05 14:22:53.349668
descriptionA container that stores numbered objects. Each object can be assigned with a unique ID.
homepagehttps://github.com/arceos-org/arceos
repositoryhttps://github.com/arceos-org/flatten_objects
max_upload_size
id1299266
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
core (github:arceos-org:core)

documentation

https://docs.rs/flatten_objects

README

flatten_objects

Crates.io Docs.rs CI

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));
Commit count: 4

cargo fmt