chiark / gitweb /
apitest: Introduce and use JsV extension set
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 May 2022 17:20:02 +0000 (18:20 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 May 2022 17:22:36 +0000 (18:22 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest/apitest.rs
apitest/atmain.rs

index d2e051b91977e530cbfae5104470800d40aeb9f8..d2a8235892e0620649639514b0847b1720a468ad 100644 (file)
@@ -128,6 +128,13 @@ impl<E:Error> From<Explode> for E {
   fn from(e: Explode) -> E { match e { } }
 }*/
 
+#[ext(pub)]
+impl JsV {
+  fn set<K: Into<String>>(&mut self, k: K, v: &JsV) {
+    self.as_object_mut().unwrap().insert(k.into(), v.clone());
+  }
+}
+
 // -------------------- Substition --------------------
 
 pub trait Substitutor {
index 35cbd52e525f9b2d7a23b0a8244ebd4ff6d595f5..ea5b155d95ff7ce14ace963d76a34133da48770a 100644 (file)
@@ -430,9 +430,7 @@ pub fn update_update_pieces<PI:Idx>(
         let d = d.as_object().unwrap();
         p.pos = coord(&d["pos"]);
         for (k,v) in d {
-          p.info
-            .as_object_mut().unwrap()
-            .insert(k.to_string(), v.clone());
+          p.info.set(k, &v);
         }
       },
       _ => {