collections/lib.rs
1// SPDX-License-Identifier: Apache-2.0
2//
3// Written in 2022-2026 by Dr. Maxim Orlovsky <orlovsky@ubideco.org>
4//
5// Copyright 2022-2026 Laboratories for Ubiquitous and Deterministic Computing,
6// Institute for Distributed and Cognitive Computing (InDCS), Switzerland.
7// All rights reserved.
8//
9// Copyright (C) 2022-2026 Dr Maxim Orlovsky.
10// All rights reserved.
11//
12// Licensed under the Apache License, Version 2.0 (the "License"); you may not
13// use this file except in compliance with the License. You may obtain a copy of
14// the License at <http://www.apache.org/licenses/LICENSE-2.0>
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
19// License for the specific language governing permissions and limitations under
20// the License.
21
22//! Generic traits for working with heap-allocated, allocator-aware and
23//! fixed-capacity collection types.
24//!
25//! [`CollectionBase`] is the constructor-free root for sequences, sets, maps
26//! and heaps. [`Collection`] and [`CollectionAlloc`] add constructors,
27//! [`CollectionBytes`] provides byte lengths for byte buffers, and
28//! [`CollectionCapacity`] provides fallible reservation and insertion.
29//! [`CollectionSet`] and [`CollectionMap`] add set and map operations, while
30//! [`CollectionEntry`] and [`MapEntry`] provide generic access to native map
31//! entry APIs.
32//!
33//! The traits themselves need neither `alloc` nor a global allocator. The
34//! `alloc` feature (implied by the default `std` feature) adds the
35//! implementations for the collections of the `alloc` crate, and the
36//! `heapless` feature adds them for fixed-capacity collections which work on
37//! targets without a heap.
38
39#![cfg_attr(docsrs, feature(doc_cfg))]
40#![cfg_attr(not(feature = "std"), no_std)]
41#![forbid(unsafe_code)]
42#![warn(missing_docs)]
43
44/// Re-export of `alloc` for no-`std` callers and macro expansion.
45#[cfg(feature = "alloc")]
46pub extern crate alloc;
47
48#[cfg(feature = "ascii")]
49/// Re-export of the optional `ascii` dependency.
50pub extern crate ascii;
51#[cfg(feature = "hashbrown")]
52/// Re-export of the optional `hashbrown` dependency.
53pub extern crate hashbrown;
54#[cfg(feature = "heapless")]
55/// Re-export of the optional `heapless` dependency.
56pub extern crate heapless;
57#[cfg(feature = "indexmap")]
58/// Re-export of the optional `indexmap` dependency.
59pub extern crate indexmap;
60
61mod byte_array;
62mod traits;
63#[cfg(feature = "alloc")]
64mod linear;
65#[cfg(feature = "alloc")]
66mod btrees;
67#[cfg(feature = "alloc")]
68mod heap;
69#[cfg(feature = "std")]
70mod hashed;
71#[cfg(feature = "hashbrown")]
72mod hashbrowns;
73#[cfg(feature = "ascii")]
74mod asciistr;
75#[cfg(feature = "indexmap")]
76mod indexed;
77
78#[cfg(feature = "alloc")]
79mod macros;
80
81#[cfg(feature = "heapless")]
82mod fixed;
83
84#[cfg(feature = "std")]
85#[doc(hidden)]
86pub extern crate std;
87
88pub use byte_array::{ByteArray, FromSliceError};
89pub use traits::{
90 Collection, CollectionAlloc, CollectionBase, CollectionBytes, CollectionCapacity,
91 CollectionEntry, CollectionMap, CollectionSet, MapEntry,
92};
93
94#[cfg(all(doctest, feature = "std"))]
95#[doc(hidden)]
96#[doc = include_str!("../README.md")]
97pub struct ReadmeDoctests;