chiark / gitweb /
utils: Loop: Provide and use Loop::ok
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 26 Feb 2021 13:00:56 +0000 (13:00 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 26 Feb 2021 13:00:56 +0000 (13:00 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest/at-otter.rs
src/utils.rs

index d5ce0ac280e0eeaa14dbda0f2a388486e13e1843..a718c9db6f337514f123c899b7905b3a9e035262 100644 (file)
@@ -144,7 +144,7 @@ impl Session {
         let puse = puse.value().as_element().ok_or(Loop::Continue)?;
         let attr = puse.attr("data-info").ok_or(Loop::Break)?;
         let info = serde_json::from_str(attr).unwrap();
-        Ok::<_,Loop<Infallible>>(PieceInfo { id: (), info })
+        Loop::ok(PieceInfo { id: (), info })
       })
       .collect()
   }
index 66cfcf3682c5bb6164effd5fcac53c11e57d3f8d..bd79992d8f5964de5d1404f68cf931f8abf3161d 100644 (file)
@@ -302,6 +302,9 @@ pub enum Loop<E> {
 impl<E> From<E> for Loop<E> {
   fn from(e: E) -> Loop<E> { Loop::Error(e) }
 }
+impl Loop<Infallible> {
+  pub fn ok<T>(t: T) -> Result<T,Loop<Infallible>> { Ok(t) }
+}
 
 pub trait IteratorExt<U,E,F>: Iterator
   where F: FnMut(Self::Item) -> Result<U,Loop<E>>,