4 releases
| 0.1.21 | Mar 30, 2025 |
|---|---|
| 0.1.2 | Mar 30, 2025 |
| 0.1.0 | Mar 29, 2025 |
| 0.1.0-alpha.1 | Mar 23, 2025 |
#1527 in Rust patterns
108 downloads per month
175KB
3.5K
SLoC
sector
A stateful vector implementation that provides different memory management behaviors through Rust traits and state machines.
Table of Contents
About
sector is a Rust library that provides a stateful vector structure (Sector<State, T>) with choosable memory allocation strategies.
Unlike Vec<T>, it allows developers to control how memory grows/shrinks.
[!NOTE] This library is under development. Expect changes and optimizations.
Features
-
Stateful Memory Management – Control memory allocation behavior dynamically.
-
Lightweight & Fast – Minimal overhead while allowing full customization.
-
No Std Support – Support for
#![no_std]environments by default.
States
Sector has 6 different states:
NormalActs like the normalstd::vec::Vec<T>.DynamicGrows the internal capacity by a factor of 2. Shrinks to 3/4 of the original capacityFixedIs not able to grow nor shrink. Returnsfalseif the capacity is full and you try to add elements.LockedDoes not allow to add or remove elements, regardless of the inner capacity.ManualRequires you to grow and shrink the inner capacity manually.TightThe inner capacity is exactly as large as the length
[!WARNING] Be careful! Zero Sized Types are treated differently by each state. Refer to the specific documentation of each state to get more information.
Usage
Add sector as a dependency in your Cargo.toml:
[dependencies]
sector = "0.1"
Basic Example
use sector::{states::Normal, Sector};
fn main() {
let mut sec: Sector<Normal, _> = Sector::new();
sec.push(10);
sec.push(20);
// Access elements
println!("First element: {:?}", sec.get(0));
}
Documentation
Generate docs locally:
cargo doc --open
Or visit the documentation online:
Contributing
Contributions are welcome!
Roadmap
- Basic stateful vector implementation
- Capacity management
-
no_stdsupport - Benchmarks & optimizations
License
This project is dual licensed:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)