From 785cef1d3bbd682df34c046cfe5fbab48964c76e Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Thu, 15 Oct 2020 23:55:10 +0500 Subject: [PATCH] Add method config::Config.public_path() --- src/config.rs | 13 +++++++++++++ src/main.rs | 1 + 2 files changed, 14 insertions(+) diff --git a/src/config.rs b/src/config.rs index 038b85c..050f8a7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -105,6 +105,19 @@ impl Config { .port(self.port) } + pub fn public_path(&self) -> Result { + let mut result_path_buf = std::path::PathBuf::new(); + result_path_buf.push(self.root.to_string()); + result_path_buf.push("public"); + + let result_str = match result_path_buf.to_str() { + None => return Err(()), + Some(value) => value, + }; + + Ok(result_str.to_string()) + } + pub fn use_env_for_root(&mut self) { self.root = match std::env::var("ROOT") { Err(_) => return, diff --git a/src/main.rs b/src/main.rs index 5e55261..9fd1d11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,5 +20,6 @@ fn main() { dotenv::dotenv().unwrap(); let config = config::Config::from_env().unwrap(); println!("Running with {:#?}", config); + println!("Public path: {:#?}", config.public_path().unwrap()); web::rocket(config).launch(); }