Skip to content

Commit

Permalink
chore: use Vec<Row> methods for JsonStream
Browse files Browse the repository at this point in the history
  • Loading branch information
ynqa committed Dec 15, 2024
1 parent a367af6 commit 9364611
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
19 changes: 19 additions & 0 deletions promkit/src/core/jsonstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl JsonStream {
}

impl JsonStream {
/// Returns a reference to the underlying vector of rows.
pub fn rows(&self) -> &[Row] {
&self.rows
}
Expand All @@ -35,6 +36,12 @@ impl JsonStream {
self.position = index;
}

/// Sets the visibility of all rows in JSON stream.
pub fn set_nodes_visibility(&mut self, collapsed: bool) {
self.rows.set_rows_visibility(collapsed);
self.position = 0;
}

/// Moves the cursor backward through JSON stream.
pub fn backward(&mut self) -> bool {
let index = self.rows.up(self.position);
Expand All @@ -43,11 +50,23 @@ impl JsonStream {
ret
}

/// Moves the cursor to the head position in JSON stream.
pub fn head(&mut self) -> bool {
self.position = self.rows.head();
true
}

/// Moves the cursor forward through JSON stream.
pub fn forward(&mut self) -> bool {
let index = self.rows.down(self.position);
let ret = index != self.position;
self.position = index;
ret
}

/// Moves the cursor to the last position in JSON stream.
pub fn tail(&mut self) -> bool {
self.position = self.rows.tail();
true
}
}
4 changes: 2 additions & 2 deletions promkit/src/jsonz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub trait RowOperation {
fn down(&self, current: usize) -> usize;
fn tail(&self) -> usize;
fn toggle(&mut self, current: usize) -> usize;
fn set_nodes_visibility(&mut self, collapsed: bool);
fn set_rows_visibility(&mut self, collapsed: bool);
fn extract(&self, current: usize, n: usize) -> Vec<Row>;
}

Expand Down Expand Up @@ -197,7 +197,7 @@ impl RowOperation for Vec<Row> {
}
}

fn set_nodes_visibility(&mut self, collapsed: bool) {
fn set_rows_visibility(&mut self, collapsed: bool) {
self.par_iter_mut().for_each(|row| {
if let Value::Open {
typ, close_index, ..
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod set_nodes_visibility {

let mut rows = create_rows(inputs.iter());

rows.set_nodes_visibility(true);
rows.set_rows_visibility(true);
for row in &rows {
match &row.v {
Value::Open { collapsed, .. } | Value::Close { collapsed, .. } => {
Expand All @@ -44,7 +44,7 @@ mod set_nodes_visibility {
}
}

rows.set_nodes_visibility(false);
rows.set_rows_visibility(false);
for row in &rows {
match &row.v {
Value::Open { collapsed, .. } | Value::Close { collapsed, .. } => {
Expand Down

0 comments on commit 9364611

Please sign in to comment.