cleanup
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 3 Jan 2026 22:39:18 +0000 (14:39 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 3 Jan 2026 22:39:18 +0000 (14:39 -0800)
rust/pspp/src/spv/read/legacy_xml.rs

index 2610c0e0f48778c0edacfc7f064407992812dbf0..4856bd962347cb1072050ecc61ed2f4b81ea800e 100644 (file)
@@ -244,30 +244,25 @@ impl Visualization {
         data: IndexMap<String, IndexMap<String, Vec<Datum<String>>>>,
         warn: &mut dyn FnMut(LegacyXmlWarning),
     ) -> BTreeMap<&str, Series> {
-        let mut source_variables = Vec::new();
-        let mut derived_variables = Vec::new();
+        let mut variables: Vec<&dyn Variable> = Vec::new();
         for child in &self.children {
             match child {
-                VisChild::SourceVariable(source_variable) => source_variables.push(source_variable),
-                VisChild::DerivedVariable(derived_variable) => {
-                    derived_variables.push(derived_variable)
-                }
+                VisChild::SourceVariable(source_variable) => variables.push(source_variable),
+                VisChild::DerivedVariable(derived_variable) => variables.push(derived_variable),
                 _ => (),
             }
         }
         let mut series = BTreeMap::<&str, Series>::new();
-        while let n = source_variables.len() + derived_variables.len()
+        while let n = variables.len()
             && n > 0
         {
-            source_variables.retain(|sv| !sv.decode(&data, &mut series));
-            derived_variables.retain(|dv| !dv.decode(&mut series, warn));
+            variables.retain(|variable| !variable.decode(&data, &mut series, warn));
 
-            if n == source_variables.len() + derived_variables.len() {
+            if n == variables.len() {
                 warn(LegacyXmlWarning::UnresolvedDependencies(
-                    source_variables
+                    variables
                         .iter()
-                        .map(|sv| sv.variable.clone())
-                        .chain(derived_variables.iter().map(|dv| dv.id.clone()))
+                        .map(|variable| variable.name().into())
                         .collect(),
                 ));
                 break;
@@ -823,6 +818,16 @@ impl VisChild {
     }
 }
 
+trait Variable {
+    fn decode<'a>(
+        &'a self,
+        data: &IndexMap<String, IndexMap<String, Vec<Datum<String>>>>,
+        series: &mut BTreeMap<&'a str, Series>,
+        warn: &mut dyn FnMut(LegacyXmlWarning),
+    ) -> bool;
+    fn name(&self) -> &str;
+}
+
 #[derive(Deserialize, Debug)]
 #[serde(rename_all = "camelCase")]
 struct SourceVariable {
@@ -861,10 +866,13 @@ impl SourceVariable {
             &[]
         }
     }
+}
+impl Variable for SourceVariable {
     fn decode<'a>(
         &'a self,
         data: &IndexMap<String, IndexMap<String, Vec<Datum<String>>>>,
         series: &mut BTreeMap<&'a str, Series>,
+        _warn: &mut dyn FnMut(LegacyXmlWarning),
     ) -> bool {
         let label_series = if let Some(label_variable) = &self.label_variable {
             if let Some(label_series) = series.get(label_variable.references.as_str()) {
@@ -914,6 +922,9 @@ impl SourceVariable {
         );
         true
     }
+    fn name(&self) -> &str {
+        &self.variable
+    }
 }
 
 #[derive(Deserialize, Debug)]
@@ -931,9 +942,10 @@ struct DerivedVariable {
     value_map: Vec<ValueMapEntry>,
 }
 
-impl DerivedVariable {
+impl Variable for DerivedVariable {
     fn decode<'a>(
         &'a self,
+        _data: &IndexMap<String, IndexMap<String, Vec<Datum<String>>>>,
         series: &mut BTreeMap<&'a str, Series>,
         warn: &mut dyn FnMut(LegacyXmlWarning),
     ) -> bool {
@@ -994,6 +1006,9 @@ impl DerivedVariable {
         );
         true
     }
+    fn name(&self) -> &str {
+        &self.id
+    }
 }
 
 #[derive(Deserialize, Debug)]