chiark / gitweb /
sse.rs: code motion
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 11 Jul 2020 22:56:01 +0000 (23:56 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 11 Jul 2020 22:56:01 +0000 (23:56 +0100)
src/sse.rs

index 71d539ca1dbd3214d643eb707158a2ffe32d21cb..4b57ba57edbf8aa3d60e5eef2c540d7b42618c21 100644 (file)
@@ -1,41 +1,20 @@
 
 use crate::imports::*;
 
+use vecdeque_stableix::StableIndexOffset;
+use std::ops::Neg;
+
+// ---------- basic definitions ----------
+
 #[derive(Copy,Clone,Debug,Eq,PartialEq,Ord,PartialOrd)]
 #[derive(Serialize,Deserialize)]
 #[serde(transparent)]
 pub struct UpdateId (i64);
 
-use vecdeque_stableix::StableIndexOffset;
-use std::ops::Neg;
-
 const UPDATE_READER_SIZE : usize = 1024*32;
 const UPDATE_MAX_FRAMING_SIZE : usize = 200;
 const UPDATE_KEEPALIVE : Duration = Duration::from_secs(14);
 
-impl Neg for UpdateId {
-  type Output = Self;
-  fn neg(self) -> Self { UpdateId(-self.0) }
-}
-
-impl Display for UpdateId {
-  fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
-    Display::fmt(&self.0,f)
-  }
-}
-
-impl StableIndexOffset for UpdateId {
-  fn try_increment(&mut self) -> Option<()> { self.0.try_increment() }
-  fn try_decrement(&mut self) -> Option<()> { self.0.try_decrement() }
-  fn index_input(&self, input: Self) -> Option<usize> {
-    self.0.index_input(input.0)
-  }
-  fn index_output(&self, inner: usize) -> Option<Self> {
-    self.0.index_output(inner).map(|v| UpdateId(v))
-  }
-  fn zero() -> Self { UpdateId(0) }
-}
-
 struct UpdateReader {
   player : PlayerId,
   client : ClientId,
@@ -148,6 +127,33 @@ impl Read for UpdateReader {
   }
 }
 
+// ---------- support implementation ----------
+
+impl Neg for UpdateId {
+  type Output = Self;
+  fn neg(self) -> Self { UpdateId(-self.0) }
+}
+
+impl Display for UpdateId {
+  fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+    Display::fmt(&self.0,f)
+  }
+}
+
+impl StableIndexOffset for UpdateId {
+  fn try_increment(&mut self) -> Option<()> { self.0.try_increment() }
+  fn try_decrement(&mut self) -> Option<()> { self.0.try_decrement() }
+  fn index_input(&self, input: Self) -> Option<usize> {
+    self.0.index_input(input.0)
+  }
+  fn index_output(&self, inner: usize) -> Option<Self> {
+    self.0.index_output(inner).map(|v| UpdateId(v))
+  }
+  fn zero() -> Self { UpdateId(0) }
+}
+
+// ---------- entrypoint for dribbling the http response ----------
+
 #[throws(OE)]
 pub fn content(iad : InstanceAccessDetails<ClientId>, gen: Generation)
   -> impl Read {