Crates.io | once-list2 |
lib.rs | once-list2 |
version | |
source | src |
created_at | 2024-12-04 08:12:07.483038 |
updated_at | 2024-12-04 08:12:07.483038 |
description | A single linked list which is backed by `OnceCell`. You can append the value to the non-mutable `OnceList`. |
homepage | |
repository | |
max_upload_size | |
id | 1471675 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | 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` |
size | 0 |
This library is a natural extension of the std::cell::OnceCell
(or its original crate once_cell
) library. This library provides a single-linked list OnceList
type that allows you to store multiple values in a single OnceList
instance even without the need for the mutability.
once_cell
- The original crate that provides a OnceCell
type. If you only need to store a single value, this crate is quite enough.elsa
- A crate that provides Frozen
collection types that allows you to store multiple values without the need for the mutability. They provides something similar to Vec
or HashMap
, so if your use case requires more than 3-ish values or you need more complex data structure than a single-linked list, then you should use this crate instead.A simple example:
use once_list2::OnceList;
// Create a new empty list. Note that the variable is immutable.
let list = OnceList::<i32>::new();
// You can push values to the list without the need for mutability.
list.push(1);
list.push(2);
// Or you can push multiple values at once.
list.extend([3, 4, 5]);
// You can iterate over the list.
assert_eq!(list.iter().copied().collect::<Vec<_>>(), vec![1, 2, 3, 4, 5]);
// Some methods are mutable only.
let mut list_mut = list;
// You can remove (take) a value from the list.
let removed = list_mut.remove(|&x| x % 2 == 0);
assert_eq!(removed, Some(2));
assert_eq!(list_mut.iter().copied().collect::<Vec<_>>(), vec![1, 3, 4, 5]);
By default, none of the features are enabled.
nightly
: Enables the nightly-only features. Particularly, uses the allocator_api
std unstable feature. Note that even without this feature, this crate still supports the allocators thanks to the allocator_api2
crate.
sync
: This library internally uses std::cell::OnceCell
which is not thread-safe. When you enable this feature, this library uses the thread-safe std::sync::OnceLock
instead.