Crate slots_slice

Crate slots_slice 

Source
Expand description

§Slots Slice

Latest Version

This is a small crate that aims provides utilities for manipulating slices of optional values, referred to as Slots<T>.

§Features

  • Conveniently manipulate slices of optional values.
  • Perform operations on slots such as counting, checking emptiness and fullness, and retrieving values and entries.
  • Macro syntax for creating and assigning.

§Usage

Bring the prelude into scope:

use slots_slice::prelude::*;

The highlight of the crate are SlotsTrait and SlotsMutTrait which add methods for accessing and manipulating slots immutably and mutably. These operate on anything that implements AsRef<[T]> so they are available right away on structs such as array and Vec<T>.

Overview of SlotsTrait:

use slots_slice::prelude::*;

let slots = [None, Some('a'), None, Some('b')];

assert_eq!(slots.count(), 2);
assert!(!slots.is_empty());
assert!(!slots.is_full());

assert_eq!(slots.front_index(true), Some(1));
assert_eq!(slots.front_value(), Some(&'a'));
assert_eq!(slots.front_entry(), Some((1, &'a')));

SlotsMutTrait provide the mutable version of SlotsTrait as well as collapse functionality.

use slots_slice::prelude::*;

let mut slots = [None, Some('a'), None, Some('b')];

assert_eq!(slots.front_value_mut(), Some(&mut 'a'));
assert_eq!(slots.front_entry_mut(), Some((1, &mut 'a')));

slots.collapse_front();

assert_eq!(slots, [Some('a'), Some('b'), None, None]);

Modules§

prelude

Macros§

array_of
Creates an array of Option<T> with specified values at corresponding indices.
replace
Replaces the values at specified indices in the slots with the provided values.

Enums§

Direction
Represents the direction for searching slots.

Traits§

SlotsMutTrait
Provides mutable access and manipulation methods for a collection of slots.
SlotsTrait
Provides utility methods for accessing and manipulating a collection of slots.

Functions§

entries
Returns an iterator over the entries (index, value) of occupied slots in the slots.
entries_mut
Returns an iterator over mutable references to the entries (index, value) of occupied slots in the slots.
indices
Returns an iterator over the indices of occupied or unoccupied slots in the slots.
values
Returns an iterator over the values of occupied slots in the slots.
values_mut
Returns an iterator over mutable references to the values of occupied slots in the slots.

Type Aliases§

Slots