Skip to main content

cossh/
lib.rs

1//! `color-ssh` library crate.
2//!
3//! This crate exposes the runtime entrypoint and shared modules used by the
4//! `cossh` binary.
5
6pub mod args;
7pub mod auth;
8mod command_path;
9pub mod config;
10mod highlighter;
11pub mod inventory;
12pub mod log;
13mod process;
14pub mod runtime;
15pub mod ssh_args;
16pub mod ssh_config;
17pub mod tui;
18mod validation;
19
20#[cfg(test)]
21mod test;
22
23use std::io;
24
25pub use runtime::run;
26
27/// Result alias for crate operations.
28pub type Result<T> = std::result::Result<T, Error>;
29
30/// Top-level error type for public crate APIs.
31#[derive(Debug)]
32pub enum Error {
33    /// Filesystem or process I/O error.
34    Io(io::Error),
35    /// Configuration load/parse error.
36    Config(config::ConfigError),
37    /// Logging initialization or write error.
38    Log(log::LogError),
39}
40
41impl std::fmt::Display for Error {
42    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43        match self {
44            Error::Io(err) => write!(f, "IO error: {}", err),
45            Error::Config(err) => write!(f, "Configuration error: {}", err),
46            Error::Log(err) => write!(f, "Logging error: {}", err),
47        }
48    }
49}
50
51impl std::error::Error for Error {}
52
53impl From<io::Error> for Error {
54    fn from(err: io::Error) -> Self {
55        Error::Io(err)
56    }
57}
58
59impl From<config::ConfigError> for Error {
60    fn from(err: config::ConfigError) -> Self {
61        Error::Config(err)
62    }
63}
64
65impl From<log::LogError> for Error {
66    fn from(err: log::LogError) -> Self {
67        Error::Log(err)
68    }
69}