Skip to content

Commit

Permalink
add sideEffect step
Browse files Browse the repository at this point in the history
  • Loading branch information
OmriSteiner committed Apr 4, 2023
1 parent b08ea08 commit 08844be
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gremlin-client/src/process/traversal/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::process::traversal::step::not::NotStep;
use crate::process::traversal::step::or::OrStep;
use crate::process::traversal::step::repeat::RepeatStep;
use crate::process::traversal::step::select::SelectStep;
use crate::process::traversal::step::side_effect::IntoSideEffectStep;
use crate::process::traversal::step::to::ToStep;
use crate::process::traversal::step::until::UntilStep;
use crate::process::traversal::step::where_step::WhereStep;
Expand Down Expand Up @@ -136,6 +137,15 @@ impl TraversalBuilder {
self
}

pub fn side_effect<A>(mut self, step: A) -> Self
where
A: IntoSideEffectStep,
{
self.bytecode
.add_step(String::from("sideEffect"), step.into_step());
self
}

pub fn with_side_effect<A>(mut self, step: (&'static str, A)) -> Self
where
A: Into<GValue> + FromGValue,
Expand Down
1 change: 1 addition & 0 deletions gremlin-client/src/process/traversal/step/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod not;
pub mod or;
pub mod repeat;
pub mod select;
pub mod side_effect;
pub mod to;
pub mod until;
pub mod where_step;
11 changes: 11 additions & 0 deletions gremlin-client/src/process/traversal/step/side_effect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::{process::traversal::TraversalBuilder, GValue};

pub trait IntoSideEffectStep {
fn into_step(self) -> Vec<GValue>;
}

impl IntoSideEffectStep for TraversalBuilder {
fn into_step(self) -> Vec<GValue> {
vec![self.bytecode.into()]
}
}

0 comments on commit 08844be

Please sign in to comment.