diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-01-25 11:02:47 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-01-25 11:02:47 +0100 |
| commit | 494920f168bccf5e4dd0b38d9d19c0f5e25c127c (patch) | |
| tree | 8a593717908505393a60a08bc5f2c32ea0e25454 /src | |
| parent | 2fdda21d13ed742bdb52ec3ba74538af83de2bf4 (diff) | |
Address more clippy
Diffstat (limited to 'src')
| -rw-r--r-- | src/configuration.rs | 12 | ||||
| -rw-r--r-- | src/proxy.rs | 8 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/configuration.rs b/src/configuration.rs index 49cd991..bd0a17f 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -9,7 +9,7 @@ use std::sync::Arc; use thiserror::Error; #[derive(Error, Debug)] -pub enum ConfigurationError { +pub enum Error { #[error("Environment variable {0} not set.")] MissingEnvVar(String), #[error("Failed to parse {0}.")] @@ -35,7 +35,7 @@ pub struct Configuration { impl Configuration { /// Creates a new configuration object by reading the environment /// variables. Exits if the right ones aren't found. - pub fn new() -> Result<Self, ConfigurationError> { + pub fn new() -> Result<Self, Error> { Ok(Configuration { imap_configuration: Arc::new(Proxy { local_port: get_env_number("LOCAL_IMAP_PORT", 143)?, @@ -56,23 +56,23 @@ impl Configuration { } /// Get an environment variable or return an error. -fn get_env_var(name: &str, default: Option<String>) -> Result<String, ConfigurationError> { +fn get_env_var(name: &str, default: Option<String>) -> Result<String, Error> { match env::var(name) { Ok(value) => Ok(value), Err(_) => match default { Some(default_value) => Ok(default_value), - None => Err(ConfigurationError::MissingEnvVar(name.to_string())), + None => Err(Error::MissingEnvVar(name.to_string())), }, } } /// Get an environment variable and parse it as a number. Return a default /// if not set. -fn get_env_number(name: &str, default: u16) -> Result<u16, ConfigurationError> { +fn get_env_number(name: &str, default: u16) -> Result<u16, Error> { match env::var(name) { Ok(value) => value .parse() - .map_err(|_| ConfigurationError::ParseError(name.to_string())), + .map_err(|_| Error::ParseError(name.to_string())), Err(_) => Ok(default), } } diff --git a/src/proxy.rs b/src/proxy.rs index a2f62e4..8348325 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -72,7 +72,7 @@ impl Server { let running_clone = Arc::clone(&running); let thread_handle = spawn(move || { - run_proxy(configuration, running_clone); + run_proxy(&configuration, &running_clone); }); Server { @@ -93,7 +93,7 @@ impl Server { /// The main loop that listens for incoming (plaintext) connections on /// `configuration.bind_address:configuration.local_port`. -fn run_proxy(configuration: Arc<Proxy>, running: Arc<AtomicBool>) { +fn run_proxy(configuration: &Arc<Proxy>, running: &Arc<AtomicBool>) { let listener = match TcpListener::bind(format!( "{}:{}", configuration.bind_address, configuration.local_port @@ -121,7 +121,7 @@ fn run_proxy(configuration: Arc<Proxy>, running: Arc<AtomicBool>) { let configuration_clone = Arc::clone(&configuration); let handle = spawn(move || { - handle_client(stream, configuration_clone); + handle_client(stream, &configuration_clone); }); active_threads.push(handle); } @@ -152,7 +152,7 @@ fn run_proxy(configuration: Arc<Proxy>, running: Arc<AtomicBool>) { } /// Handles a single client connection by bridging it (plaintext) to a TLS connection. -fn handle_client(client_stream: TcpStream, configuration: Arc<Proxy>) { +fn handle_client(client_stream: TcpStream, configuration: &Arc<Proxy>) { if let Err(e) = client_stream.set_nonblocking(true) { error!("Failed to set client stream to nonblocking: {}", e); return; |