ringstack
ringstack
[RingStack] is a tiny stack implementation which uses circular buffer.
Since [RingStack] is constructed upon a circular buffer, the oldest item automatically dropped as you [push][RingStack::push()] when the number of items has already reached its limit. (Thus [len][RingStack::len()] method saturate with that number of limit.)
And it supports [RingStack::iter()] method which returns Iterator<&T>.
It provides items one by one with historical order, latest to oldest.
([RingStack::iter_mut()] method is also available)
Though [RingStack] currently uses [Vec] as its internals, once it allocates at the timing of [new][RingStack::new()] then additional allocation never happends.
Examples
use RingStack;
let mut s = new;
assert_eq!;
s.push;
s.push;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
s.push;
s.push;
let v: = s.iter.map.collect;
assert_eq!;
s.push;
let v: = s.iter.map.collect;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Changelog
0.3.0 (2025/03/18)
- Added [
iter_mut()] and mut version of index accessing. - Added [
clone()]
0.2.0
-
Added [
len()], [get()] methods. -
Implemented [
std::ops::Index]. -
Change [
iter()] return typeChanged from
&Option<T>into&Tand it iterates only valid elements, since it returns reference ofTnotOption.
0.1.1
Make RingStack [Debug] derived
0.1.0
Initial Version
License
The MIT License (MIT)
Copyright (c) 2022 msr1k