ryo_executor/executor/registry/converters/add_item/
mod.rs1use crate::engine::ASTRegApply;
7use crate::executor::registry::converter::{ConvertError, MutationConverter};
8use crate::executor::registry::converters::ResolveTargetSymbol;
9use crate::executor::spec::MutationSpec;
10use ryo_analysis::AnalysisContext;
11use ryo_mutations::AddItemMutation;
12
13pub struct AddItemConverter;
15
16impl AddItemConverter {
17 pub fn new() -> Self {
18 Self
19 }
20}
21
22impl Default for AddItemConverter {
23 fn default() -> Self {
24 Self::new()
25 }
26}
27
28impl ResolveTargetSymbol for AddItemConverter {}
30
31impl MutationConverter for AddItemConverter {
32 fn spec_kinds(&self) -> &'static [&'static str] {
33 &["AddItem"]
34 }
35
36 fn convert_v2(
37 &self,
38 spec: &MutationSpec,
39 ctx: &AnalysisContext,
40 ) -> Result<Vec<Box<dyn ASTRegApply>>, ConvertError> {
41 match spec {
42 MutationSpec::AddItem {
43 target, content, ..
44 } => {
45 let symbol_id = self.resolve_target_symbol(target, ctx)?;
47
48 let mutation = AddItemMutation::new(symbol_id, content.clone());
49 Ok(vec![Box::new(mutation)])
50 }
51 _ => Err(ConvertError::TypeMismatch {
52 expected: "AddItem",
53 actual: spec.kind_name().to_string(),
54 }),
55 }
56 }
57}