diff --git a/src/core/jit/fixtures/jp.rs b/src/core/jit/fixtures/jp.rs index e7d44f18e3..af3050c6c0 100644 --- a/src/core/jit/fixtures/jp.rs +++ b/src/core/jit/fixtures/jp.rs @@ -8,7 +8,7 @@ use crate::core::jit::builder::Builder; use crate::core::jit::store::Store; use crate::core::jit::synth::Synth; use crate::core::jit::transform::InputResolver; -use crate::core::jit::{transform, OperationPlan, Variables}; +use crate::core::jit::{transform, Field, OperationPlan, Variables}; use crate::core::json::{JsonLike, JsonObjectLike}; use crate::core::valid::Validator; use crate::core::Transform; @@ -119,10 +119,11 @@ impl<'a, Value: Deserialize<'a> + Clone + 'a + JsonLike<'a> + std::fmt::Debug> J let ProcessedTestData { posts, users } = self.test_data.to_processed(); let vars = self.vars.clone(); - let posts_id = self.plan.find_field_path(&["posts"]).unwrap().id.to_owned(); - let users_id = self - .plan - .find_field_path(&["posts", "user"]) + let posts_id = find_field_path(&self.plan, &["posts"]) + .unwrap() + .id + .to_owned(); + let users_id = find_field_path(&self.plan, &["posts", "user"]) .unwrap() .id .to_owned(); @@ -137,3 +138,21 @@ impl<'a, Value: Deserialize<'a> + Clone + 'a + JsonLike<'a> + std::fmt::Debug> J Synth::new(&self.plan, store, vars) } } + +/// Search for a field by specified path of nested fields +pub fn find_field_path<'a, S: AsRef, T>( + plan: &'a OperationPlan, + path: &[S], +) -> Option<&'a Field> { + match path.split_first() { + None => None, + Some((name, path)) => { + let field = plan.iter_dfs().find(|field| field.name == name.as_ref())?; + if path.is_empty() { + Some(field) + } else { + find_field_path(plan, path) + } + } + } +} diff --git a/src/core/jit/model.rs b/src/core/jit/model.rs index 13dfcbb7d3..6996f7bfcb 100644 --- a/src/core/jit/model.rs +++ b/src/core/jit/model.rs @@ -366,21 +366,6 @@ impl OperationPlan { DFS { stack: vec![self.selection.iter()] } } - /// Search for a field by specified path of nested fields - pub fn find_field_path>(&self, path: &[S]) -> Option<&Field> { - match path.split_first() { - None => None, - Some((name, path)) => { - let field = self.iter_dfs().find(|field| field.name == name.as_ref())?; - if path.is_empty() { - Some(field) - } else { - self.find_field_path(path) - } - } - } - } - /// Returns number of fields in plan pub fn size(&self) -> usize { fn count(field: &Field) -> usize {