From 5d86a29e96b19c86a0b38c052fc707a0db20c1b8 Mon Sep 17 00:00:00 2001 From: Titouan Rigoudy Date: Sat, 13 Nov 2021 15:01:26 +0100 Subject: [PATCH] Run in async mode by default. --- client/src/config.rs | 8 ++++---- client/src/main.rs | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/client/src/config.rs b/client/src/config.rs index 767e9f0..9b98f0f 100644 --- a/client/src/config.rs +++ b/client/src/config.rs @@ -33,11 +33,11 @@ pub struct TomlConfig { } impl TomlConfig { - fn from_str(s: &str) -> Result { + pub fn from_str(s: &str) -> Result { toml::from_str(s) } - async fn from_file_path(path: &Path) -> anyhow::Result { + pub async fn from_file_path(path: &Path) -> anyhow::Result { let mut file = File::open(path).await.context("opening toml config file")?; @@ -88,7 +88,7 @@ impl Default for Config { impl Config { /// Builds a new config with the given `credentials` and default values. - fn new(credentials: Credentials) -> Self { + pub fn new(credentials: Credentials) -> Self { Self { credentials, server_address: "server.slsknet.org:2242".to_string(), @@ -100,7 +100,7 @@ impl Config { } /// Attempts to build a `Config` from the given `TomlConfig`. - fn from_toml(toml: TomlConfig) -> anyhow::Result { + pub fn from_toml(toml: TomlConfig) -> anyhow::Result { let credentials = Credentials::new(toml.user_name, toml.password) .context("validating credentials")?; diff --git a/client/src/main.rs b/client/src/main.rs index efb823d..ccdfb5a 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -138,19 +138,19 @@ async fn main() -> anyhow::Result<()> { .version("0.1") .author("letitz") .arg( - Arg::with_name("async") - .long("async") - .help("Use the new async engine."), + Arg::with_name("sync") + .long("sync") + .help("Use the old synchronous engine."), ) .get_matches(); - if matches.is_present("async") { - info!("Running in asynchronous mode."); - async_main().await.context("running asynchronous main") - } else { + if matches.is_present("sync") { info!("Running in synchronous mode."); tokio::task::spawn_blocking(old_main) .await .context("running synchronous main") + } else { + info!("Running in asynchronous mode."); + async_main().await.context("running asynchronous main") } }