Crate sector

Crate sector 

Source
Expand description

§Stateful Vector (Sector)

Sector is a versatile vector-like container that provides different memory management behaviors through a stateful type system. It allows precise control over allocation, growth, and shrink behavior based on the chosen state.

§Features

  • Multiple memory management strategies using distinct states.
  • Custom allocation policies, including dynamic resizing, fixed capacity, manual control, and tight packing.
  • Safe and efficient transitions between states.
  • Works in no_std by default.

§States Overview

The Sector type is parameterized over a state, which defines its behavior:

  • Normal – Behaves like a standard Vec<T>, growing dynamically as needed.
  • Dynamic – Allows manual resizing, but still provides automatic growth.
  • Fixed – Has a fixed capacity that cannot grow dynamically.
  • Tight – Optimized for minimal memory usage with exact fits.
  • Locked – Prevents modification, acting as a frozen buffer.
  • Manual – Provides explicit manual control over memory allocation.

§Example Usage

use sector::Sector;
use sector::states::Normal;

let mut vec: Sector<Normal, i32> = Sector::new();
vec.push(10);
vec.push(20);
assert_eq!(vec.pop(), Some(20));

§State Transitions

You can convert between states using transition methods:

use sector::Sector;
use sector::states::{Normal, Fixed};

let normal_vec: Sector<Normal, i32> = Sector::new();
let fixed_vec: Sector<Fixed, i32> = normal_vec.to_fixed();

§no_std Compatibility

The crate supports by default no_std apps. So just add it using:

[dependencies]
sector = { version = "0.1"}

§Modules

  • components – Internal traits defining vector operations.
  • sector – Core implementation of Sector.
  • states – Definitions of different memory management states.

License: MIT & APACHE 2.0

Repository: GitHub

Modules§

components
states

Structs§

Sector