From e855c31f38d4626aa84b5cfade58e41083b6864e Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Sat, 3 Jun 2023 02:11:36 +0100 Subject: [PATCH] Minor formatting and style changes --- src/config.rs | 6 +++--- src/instance_info.rs | 1 + src/post.rs | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index a02ea88..e2891ea 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,7 +11,7 @@ pub(crate) static CONFIG: Lazy = Lazy::new(Config::load); // This serves as the frontend for the Pushshift API - on removed comments, this URL will // be the base of a link, to display removed content (on another site). -pub(crate) static DEFAULT_PUSHSHIFT_FRONTEND: &str = "www.unddit.com"; +pub(crate) const DEFAULT_PUSHSHIFT_FRONTEND: &str = "www.unddit.com"; /// Stores the configuration parsed from the environment variables and the /// config file. `Config::Default()` contains None for each setting. @@ -79,7 +79,6 @@ impl Config { // both are `None`, return a `None` via the `map_or_else` function let parse = |key: &str| -> Option { var(key).ok().map_or_else(|| get_setting_from_config(key, &config), Some) }; - Self { sfw_only: parse("LIBREDDIT_SFW_ONLY"), default_theme: parse("LIBREDDIT_DEFAULT_THEME"), @@ -130,7 +129,8 @@ pub(crate) fn get_setting(name: &str) -> Option { use {sealed_test::prelude::*, std::fs::write}; #[test] -fn test_deserialize() { // Must handle empty input +fn test_deserialize() { + // Must handle empty input let result = toml::from_str::(""); assert!(result.is_ok(), "Error: {}", result.unwrap_err()); } diff --git a/src/instance_info.rs b/src/instance_info.rs index 4df314a..daa06e2 100644 --- a/src/instance_info.rs +++ b/src/instance_info.rs @@ -123,6 +123,7 @@ impl InstanceInfo { ["Compile mode", &self.compile_mode], ["SFW only", &convert(&self.config.sfw_only)], ["Pushshift frontend", &convert(&self.config.pushshift)], + //TODO: fallback to crate::config::DEFAULT_PUSHSHIFT_FRONTEND ]) .with_header_row(["Settings"]), ); diff --git a/src/post.rs b/src/post.rs index c2e3d4f..5478d22 100644 --- a/src/post.rs +++ b/src/post.rs @@ -1,6 +1,6 @@ // CRATES use crate::client::json; -use crate::config::{get_setting, DEFAULT_PUSHSHIFT_FRONTEND}; +use crate::config::get_setting; use crate::server::RequestExt; use crate::subreddit::{can_access_quarantine, quarantine}; use crate::utils::{ @@ -126,7 +126,7 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str, let body = if (val(&comment, "author") == "[deleted]" && val(&comment, "body") == "[removed]") || val(&comment, "body") == "[ Removed by Reddit ]" { format!( "

[removed] — view removed comment

", - get_setting("LIBREDDIT_PUSHSHIFT_FRONTEND").unwrap_or(String::from(DEFAULT_PUSHSHIFT_FRONTEND)), + get_setting("LIBREDDIT_PUSHSHIFT_FRONTEND").unwrap_or(String::from(crate::config::DEFAULT_PUSHSHIFT_FRONTEND)), post_link, id )