Skip to content

Commit 792e0b6

Browse files
committed
Almost done with JsonBuffer
Signed-off-by: Michael X. Grey <[email protected]>
1 parent b21c218 commit 792e0b6

File tree

3 files changed

+267
-34
lines changed

3 files changed

+267
-34
lines changed

src/buffer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub use manage_buffer::*;
5656

5757
#[cfg(feature = "diagram")]
5858
mod json_buffer;
59+
#[cfg(feature = "diagram")]
60+
pub use json_buffer::*;
5961

6062
/// A buffer is a special type of node within a workflow that is able to store
6163
/// and release data. When a session is finished, the buffered data from the

src/buffer/any_buffer.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ impl<T: 'static + Send + Sync + Any> From<BufferKey<T>> for AnyBufferKey {
137137
}
138138
}
139139

140-
/// Similar to [`BufferMut`][crate::BufferMut], but this can be unlocked with a
141-
/// [`DynBufferKey`], so it can work for any buffer regardless of the data type
140+
/// Similar to [`BufferMut`][crate::BufferMut], but this can be unlocked with an
141+
/// [`AnyBufferKey`], so it can work for any buffer regardless of the data type
142142
/// inside.
143143
pub struct AnyBufferMut<'w, 's, 'a> {
144144
storage: Box<dyn AnyBufferManagement + 'a>,
@@ -159,18 +159,18 @@ impl<'w, 's, 'a> AnyBufferMut<'w, 's, 'a> {
159159
self
160160
}
161161

162-
/// Look at the oldest item in the buffer.
162+
/// Look at the oldest message in the buffer.
163163
pub fn oldest(&self) -> Option<AnyMessageRef<'_>> {
164164
self.storage.any_oldest(self.session)
165165
}
166166

167-
/// Look at the newest item in the buffer.
167+
/// Look at the newest message in the buffer.
168168
pub fn newest(&self) -> Option<AnyMessageRef<'_>> {
169169
self.storage.any_newest(self.session)
170170
}
171171

172-
/// Borrow an item from the buffer. Index 0 is the oldest item in the buffer
173-
/// with the highest index being the newest item in the buffer.
172+
/// Borrow a message from the buffer. Index 0 is the oldest message in the buffer
173+
/// with the highest index being the newest message in the buffer.
174174
pub fn get(&self, index: usize) -> Option<AnyMessageRef<'_>> {
175175
self.storage.any_get(self.session, index)
176176
}
@@ -194,39 +194,40 @@ impl<'w, 's, 'a> AnyBufferMut<'w, 's, 'a> {
194194
.unwrap_or(Gate::Open)
195195
}
196196

197-
/// Modify the oldest item in the buffer.
197+
/// Modify the oldest message in the buffer.
198198
pub fn oldest_mut(&mut self) -> Option<AnyMessageMut<'_>> {
199199
self.modified = true;
200200
self.storage.any_oldest_mut(self.session)
201201
}
202202

203-
/// Modify the newest item in the buffer.
203+
/// Modify the newest message in the buffer.
204204
pub fn newest_mut(&mut self) -> Option<AnyMessageMut<'_>> {
205205
self.modified = true;
206206
self.storage.any_newest_mut(self.session)
207207
}
208208

209-
/// Modify an item in the buffer. Index 0 is the oldest item in the buffer
210-
/// with the highest index being the newest item in the buffer.
209+
/// Modify a message in the buffer. Index 0 is the oldest message in the buffer
210+
/// with the highest index being the newest message in the buffer.
211211
pub fn get_mut(&mut self, index: usize) -> Option<AnyMessageMut<'_>> {
212212
self.modified = true;
213213
self.storage.any_get_mut(self.session, index)
214214
}
215215

216+
/// Drain a range of messages out of the buffer.
216217
pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> DrainAnyBuffer<'_> {
217218
self.modified = true;
218219
DrainAnyBuffer {
219220
interface: self.storage.any_drain(self.session, AnyRange::new(range))
220221
}
221222
}
222223

223-
/// Pull the oldest item from the buffer.
224+
/// Pull the oldest message from the buffer.
224225
pub fn pull(&mut self) -> Option<AnyMessage> {
225226
self.modified = true;
226227
self.storage.any_pull(self.session)
227228
}
228229

229-
/// Pull the item that was most recently put into the buffer (instead of the
230+
/// Pull the message that was most recently put into the buffer (instead of the
230231
/// oldest, which is what [`Self::pull`] gives).
231232
pub fn pull_newest(&mut self) -> Option<AnyMessage> {
232233
self.modified = true;
@@ -398,7 +399,7 @@ pub(crate) struct AnyRange {
398399
}
399400

400401
impl AnyRange {
401-
fn new<T: std::ops::RangeBounds<usize>>(range: T) -> Self {
402+
pub(crate) fn new<T: std::ops::RangeBounds<usize>>(range: T) -> Self {
402403
AnyRange {
403404
start_bound: range.start_bound().map(|x| *x),
404405
end_bound: range.end_bound().map(|x| *x),

0 commit comments

Comments
 (0)