chiark / gitweb /
Move TopLevelError out into its own source file.
authorSimon Tatham <anakin@pobox.com>
Thu, 1 Feb 2024 08:06:15 +0000 (08:06 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 2 Feb 2024 12:19:07 +0000 (12:19 +0000)
Now lib.rs is just a list of declarations of other modules, which
seems cleaner.

src/auth.rs
src/client.rs
src/config.rs
src/lib.rs
src/main.rs
src/top_level_error.rs [new file with mode: 0644]
src/tui.rs

index 69a6dcacbc334b181a15404d923c071e7112c346..578d6554b36cafb77212bb423850a7b268126ec5 100644 (file)
@@ -9,7 +9,7 @@ pub enum AuthError {
     SaveFailed(String),
 }
 
-impl super::TopLevelErrorCandidate for AuthError {}
+impl super::top_level_error::TopLevelErrorCandidate for AuthError {}
 
 impl std::fmt::Display for AuthError {
     fn fmt(
index 558e91999fefd7685b6de6efa2c5c42f377c384c..e85008ebe145988c9843b4c483e28d1ff848bda5 100644 (file)
@@ -166,7 +166,7 @@ pub enum ClientError {
     Consistency(String),       // just error message
 }
 
-impl super::TopLevelErrorCandidate for ClientError {}
+impl super::top_level_error::TopLevelErrorCandidate for ClientError {}
 
 impl From<reqwest::Error> for ClientError {
     fn from(err: reqwest::Error) -> Self {
index 3ea64a0f7f7d46a440693101132770d512b465c4..a59b793b3024a6613efc65ed5318bd6d8b6cbb97 100644 (file)
@@ -14,7 +14,7 @@ pub enum ConfigError {
     Env(std::env::VarError),
 }
 
-impl super::TopLevelErrorCandidate for ConfigError {}
+impl super::top_level_error::TopLevelErrorCandidate for ConfigError {}
 
 impl std::fmt::Display for ConfigError {
     fn fmt(
index 422ad0aa8369b0eeb0b3c23d4863a015b5ebf7dd..91110dceaf305711b543da49566589806de76561 100644 (file)
@@ -12,44 +12,6 @@ pub mod options;
 pub mod posting;
 pub mod scan_re;
 pub mod text;
+pub mod top_level_error;
 pub mod tui;
 pub mod types;
-
-#[derive(Debug)]
-pub struct TopLevelError {
-    prefix: String,
-    message: String,
-}
-
-impl std::fmt::Display for TopLevelError {
-    fn fmt(
-        &self,
-        f: &mut std::fmt::Formatter<'_>,
-    ) -> Result<(), std::fmt::Error> {
-        write!(f, "mastodonochrome: {}{}", self.prefix, self.message)
-    }
-}
-
-trait TopLevelErrorCandidate: std::fmt::Display {
-    fn get_prefix() -> String {
-        "error: ".to_owned()
-    }
-}
-
-impl<E: TopLevelErrorCandidate> From<E> for TopLevelError {
-    fn from(err: E) -> Self {
-        TopLevelError {
-            prefix: E::get_prefix(),
-            message: err.to_string(),
-        }
-    }
-}
-
-impl TopLevelErrorCandidate for clap::error::Error {
-    // clap prints its own "error: "
-    fn get_prefix() -> String {
-        "".to_owned()
-    }
-}
-
-impl TopLevelErrorCandidate for std::io::Error {}
index 9403267a6e6415bf147dc2cda05c0fc7476259d7..6f2e75b22b1aabed9dd92d4584d77b8773575868 100644 (file)
@@ -3,7 +3,7 @@ use std::process::ExitCode;
 
 use mastodonochrome::config::ConfigLocation;
 use mastodonochrome::tui::Tui;
-use mastodonochrome::TopLevelError;
+use mastodonochrome::top_level_error::TopLevelError;
 
 #[derive(Parser, Debug)]
 struct Args {
diff --git a/src/top_level_error.rs b/src/top_level_error.rs
new file mode 100644 (file)
index 0000000..e620ae3
--- /dev/null
@@ -0,0 +1,38 @@
+#[derive(Debug)]
+pub struct TopLevelError {
+    prefix: String,
+    message: String,
+}
+
+impl std::fmt::Display for TopLevelError {
+    fn fmt(
+        &self,
+        f: &mut std::fmt::Formatter<'_>,
+    ) -> Result<(), std::fmt::Error> {
+        write!(f, "mastodonochrome: {}{}", self.prefix, self.message)
+    }
+}
+
+pub trait TopLevelErrorCandidate: std::fmt::Display {
+    fn get_prefix() -> String {
+        "error: ".to_owned()
+    }
+}
+
+impl<E: TopLevelErrorCandidate> From<E> for TopLevelError {
+    fn from(err: E) -> Self {
+        TopLevelError {
+            prefix: E::get_prefix(),
+            message: err.to_string(),
+        }
+    }
+}
+
+impl TopLevelErrorCandidate for clap::error::Error {
+    // clap prints its own "error: "
+    fn get_prefix() -> String {
+        "".to_owned()
+    }
+}
+
+impl TopLevelErrorCandidate for std::io::Error {}
index dfeab48f1f59951b496a2cc2159f758a0f8b8528..fe1d615714f46015ee2a0b53e6ad40c97d83bef4 100644 (file)
@@ -219,7 +219,7 @@ impl TuiError {
     }
 }
 
-impl super::TopLevelErrorCandidate for TuiError {}
+impl super::top_level_error::TopLevelErrorCandidate for TuiError {}
 
 impl From<String> for TuiError {
     fn from(message: String) -> Self {