1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
use ;
/// A lightweight abstraction over [`VecDeque`] that preserves stable indexing after elements
/// are removed from the front.
///
/// Unlike a plain [`VecDeque`], where removing elements from the front causes all remaining
/// elements to shift their indices, `RingBuffer` maintains stable absolute indices by tracking
/// an internal offset. This allows you to refer to elements by their original insertion position
/// even after earlier elements have been removed.
///
/// # Example
///
/// ```
/// # use kosame_dsl::pretty::RingBuffer;
/// let mut buffer = RingBuffer::new();
/// buffer.push_back("first"); // index 0
/// buffer.push_back("second"); // index 1
/// buffer.push_back("third"); // index 2
///
/// buffer.pop_front(); // removes "first"
///
/// // Index 1 still refers to "second" (not shifted to 0)
/// assert_eq!(buffer[1], "second");
/// assert_eq!(buffer[2], "third");
/// ```
/// Provides immutable indexing using absolute indices.
///
/// The index parameter should be the absolute position (original insertion index),
/// not relative to the current buffer state. The implementation automatically adjusts
/// for elements that have been popped from the front.
///
/// # Panics
///
/// Panics if the index is out of bounds (either before the current offset or beyond
/// the end of the buffer).
/// Provides mutable indexing using absolute indices.
///
/// The index parameter should be the absolute position (original insertion index),
/// not relative to the current buffer state. The implementation automatically adjusts
/// for elements that have been popped from the front.
///
/// # Panics
///
/// Panics if the index is out of bounds (either before the current offset or beyond
/// the end of the buffer).