Expand description
Circular (ring) sequence operations for Rust slices.
ring-seq extends [T] (and, through Deref coercion, Vec<T>,
arrays, and Box<[T]>) with operations that treat the sequence as
circular — the element after the last wraps back to the first.
§Quick start
use ring_seq::RingSeq;
// Indexing wraps around
assert_eq!(*[10, 20, 30].apply_o(4), 20);
// Rotation produces a new Vec
assert_eq!([0, 1, 2].rotate_right(1), vec![2, 0, 1]);
// Comparison up to rotation
assert!([0, 1, 2].is_rotation_of(&[2, 0, 1]));
// Canonical (necklace) form for deduplication
assert_eq!([2, 0, 1].canonical(), vec![0, 1, 2]);
// Symmetry detection
assert_eq!([0, 1, 0, 1].rotational_symmetry(), 2);§Naming convention
Most methods use plain, Rust-idiomatic names (take_while, span,
contains_slice, etc.) since every method on RingSeq is circular by
definition.
A few methods carry a distinguishing name to avoid confusion with standard-library counterparts:
apply_o— circular element access (the_osignals a circular index).slice_o— circular slicing (sliceis a fundamental Rust type).circular_windows,circular_chunks,circular_enumerate— circular variants ofwindows,chunks, andenumerate.
§Interaction with [T]::rotate_left / [T]::rotate_right
The standard library provides in-place rotate_left(&mut self, mid: usize)
and rotate_right(&mut self, mid: usize) on mutable slices. This crate’s
methods have the same names but differ in signature: they take &self and
an isize step (which may be negative), and return a new Vec<T>. The
compiler resolves calls unambiguously based on mutability and argument type.
If you need to force the circular variant on a &mut slice, call
.as_ref() or reborrow as &*slice first.
Structs§
- Reflections
- The two orientations of a circular sequence: the original and its reflection at index 0.
- Reversions
- The two orientations of a circular sequence: the original and its reversal.
- Rotations
- All rotations of a circular sequence.
- Rotations
AndReflections - All rotations of the original sequence followed by all rotations of its reflection.
- SlidingO
- Sliding windows over a circular sequence.
Enums§
- Axis
Location - A location on a circular sequence where a reflectional-symmetry axis passes.
Traits§
- RingSeq
- Circular (ring) sequence operations on
[T].