Skip to content

Commit

Permalink
Make PointStamp::vector private
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmcsherry committed Jan 30, 2024
1 parent 74435b4 commit 24244a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
10 changes: 6 additions & 4 deletions src/dynamic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ where
input.for_each(|cap, data| {
data.swap(&mut vector);
let mut new_time = cap.time().clone();
new_time.inner.vector.truncate(level - 1);
new_time.inner.enforce();
let mut vec = std::mem::take(&mut new_time.inner).into_vec();
vec.truncate(level - 1);
new_time.inner = PointStamp::new(vec);
let new_cap = cap.delayed(&new_time);
for (_data, time, _diff) in vector.iter_mut() {
time.inner.vector.truncate(level - 1);
time.inner.enforce();
let mut vec = std::mem::take(&mut time.inner).into_vec();
vec.truncate(level - 1);
time.inner = PointStamp::new(vec);
}
output.session(&new_cap).give_vec(&mut vector);
});
Expand Down
23 changes: 13 additions & 10 deletions src/dynamic/pointstamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,26 @@ use serde::{Deserialize, Serialize};
)]
pub struct PointStamp<T> {
/// A sequence of timestamps corresponding to timestamps in a sequence of nested scopes.
pub vector: Vec<T>,
vector: Vec<T>,
}

impl<T: Timestamp> PointStamp<T> {
/// Create a new sequence.
///
/// This method will modify `vector` to ensure it does not end with `T::minimum()`.
pub fn new(vector: Vec<T>) -> Self {
let mut result = PointStamp { vector };
result.enforce();
result
}
/// Enforces that `self` not end with `T::minimum()` by popping elements until it is true.
pub fn enforce(&mut self) {
while self.vector.last() == Some(&T::minimum()) {
self.vector.pop();
pub fn new(mut vector: Vec<T>) -> Self {
while vector.last() == Some(&T::minimum()) {
vector.pop();
}
PointStamp { vector }
}
/// Returns the wrapped vector.
///
/// This method is the support way to mutate the contents of `self`, by extracting
/// the vector and then re-introducting it with `PointStamp::new` to re-establish
/// the invariant that the vector not end with `T::minimum`.
pub fn into_vec(self) -> Vec<T> {
self.vector
}
}

Expand Down

0 comments on commit 24244a9

Please sign in to comment.