chiark / gitweb /
apitest: Make setup_static_users less lifetimes-entangled
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Apr 2021 17:32:54 +0000 (18:32 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Apr 2021 17:50:57 +0000 (18:50 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest/apitest.rs
apitest/at-otter.rs
wdriver/wdriver.rs

index 27c0f87322d1e709813558535a387127a831be2f..fa3b3327ac5c1a1bb52dddf2c76ca9849426b5b1 100644 (file)
@@ -725,10 +725,8 @@ pub struct StaticUserSetup {
 
 impl DirSubst {
   #[throws(AE)]
-  pub fn setup_static_users
-    <W, F: FnMut(StaticUserSetup) -> Result<W, AE>>
-    (&mut self, layout: PresentationLayout, mut f: F)
-     -> Vec<W>
+  pub fn setup_static_users(&mut self, layout: PresentationLayout)
+     -> Vec<StaticUserSetup>
   {
     #[throws(AE)]
     fn mk(su: &DirSubst, layout: PresentationLayout, u: StaticUser)
@@ -755,13 +753,12 @@ impl DirSubst {
     StaticUser::iter().map(
       |u| (||{
         let ssu = mk(self, layout, u).context("create")?;
-        let w = f(ssu).context("set up")?;
-        Ok::<_,AE>(w)
+        Ok::<_,AE>(ssu)
       })()
         .with_context(|| format!("{:?}", u))
         .context("make static user")
     )
-      .collect::<Result<Vec<W>,AE>>()?
+      .collect::<Result<Vec<StaticUserSetup>,AE>>()?
   }
 }
 
index 7acb3b145561a2817d167a5425fb59fa5a163c5e..e5ffb3dab5a10740dad6d48c705f6162bce3d11e 100644 (file)
@@ -646,11 +646,10 @@ fn main() {
       &mut |_|false
     )?;
     let spec = su.ds.game_spec_data()?;
-    let [alice, bob]: [Player; 2] = su.ds.setup_static_users(
-      default(),
-      |sus| Ok(Player { nick: sus.nick, url: sus.url })
-    )?
-      .try_into().unwrap();
+    let [alice, bob]: [Player; 2] =
+      su.ds.setup_static_users(default())?
+      .into_iter().map(|sus| Player { nick: sus.nick, url: sus.url })
+      .collect::<ArrayVec<_>>().into_inner().unwrap();
     
     let su_rc = Rc::new(RefCell::new(su));
     tests(Ctx { opts, spec, su_rc, alice, bob })?;
index 171389f757834176cf0940ae92d08d86bf7abe2f..8a8b8e50f6ce9b2a3c70e9e4bfc160666e800c67 100644 (file)
@@ -674,12 +674,16 @@ pub fn setup(exe_module_path: &str) -> (Setup, Instance) {
 impl Setup {
   #[throws(AE)]
   pub fn setup_static_users(&mut self, instance: &Instance) -> Vec<Window> {
-    self.core.ds.clone().setup_static_users(self.opts.layout, |sus|{
+    self.core.ds.clone()
+      .setup_static_users(self.opts.layout)?
+      .into_iter().map(|sus|
+    {
       let w = self.new_window(instance, sus.nick)?;
       self.w(&w)?.get(sus.url)?;
       self.w(&w)?.screenshot("initial", log::Level::Trace)?;
-      Ok(w)
-    })?
+      Ok::<_,AE>(w)
+    })
+      .collect::<Result<_,_>>()?
   }
 }