chiark / gitweb /
move implementation
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 22 Jul 2020 22:35:04 +0000 (23:35 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 22 Jul 2020 22:35:04 +0000 (23:35 +0100)
src/cmdlistener.rs
src/commands.rs

index ef047d92a000ba525d18989568b37f0bdaa401b6..e2c64ba8f1cac9682fadfc2c3cc43fbf22210585 100644 (file)
@@ -40,6 +40,36 @@ impl CommandStream {
   }
 }
 
+impl From<serde_json::Error> for MgmtError {
+  fn from(je: serde_json::Error) -> ME {
+    ParseFailed(format!("{}", &je))
+  }
+}
+
+use MgmtCommand::*;
+use MgmtResponse::*;
+use MgmtError::*;
+
+type ME = MgmtError;
+
+pub fn decode_and_process(s: &str) -> MgmtResponse {
+  self::decode_process_inner(s)
+    .unwrap_or_else(|e| MgmtResponse::Error(format!("{}", e)))
+}
+
+#[throws(ME)]
+fn decode_process_inner(s: &str)-> MgmtResponse {
+  let cmd : MgmtCommand = serde_json::from_str(s)?;
+  execute(cmd)?
+}
+
+#[throws(ME)]
+fn execute(cmd: MgmtCommand) -> MgmtResponse {
+  match cmd {
+    Noop { } => Fine { },
+  }
+}
+
 impl CommandListener {
   #[throws(StartupError)]
   pub fn new() -> Self {
index 38e9d1ee435577a04b79d720c53ec805c8bfbaf4..a5ba28d4b4192581c27e59bdcd99da4e363246d2 100644 (file)
@@ -13,36 +13,8 @@ pub enum MgmtResponse {
 }
 
 #[derive(Debug,Error)]
-enum MgmtError {
+pub enum MgmtError {
   ParseFailed(String),
 }
 display_as_debug!{MgmtError}
-type ME = MgmtError;
 
-  use MgmtCommand::*;
-  use MgmtResponse::*;
-  use MgmtError::*;
-
-impl From<serde_json::Error> for MgmtError {
-  fn from(je: serde_json::Error) -> ME {
-    ParseFailed(format!("{}", &je))
-  }
-}
-
-pub fn decode_and_process(s: &str) -> MgmtResponse {
-  self::decode_process_inner(s)
-    .unwrap_or_else(|e| MgmtResponse::Error(format!("{}", e)))
-}
-
-#[throws(ME)]
-fn decode_process_inner(s: &str)-> MgmtResponse {
-  let cmd : MgmtCommand = serde_json::from_str(s)?;
-  execute(cmd)?
-}
-
-#[throws(ME)]
-fn execute(cmd: MgmtCommand) -> MgmtResponse {
-  match cmd {
-    Noop { } => Fine { },
-  }
-}