From bc00064731f8a0924d748e64c6ee75473de053ef Mon Sep 17 00:00:00 2001 From: Integral Date: Sun, 8 Dec 2024 05:32:46 +0800 Subject: [PATCH] refactor: replace static with const for global constants (#2729) --- components/config/src/config/mod.rs | 2 +- components/content/src/front_matter/section.rs | 2 +- components/imageproc/src/processor.rs | 2 +- components/imageproc/tests/resize_image.rs | 2 +- components/markdown/benches/all.rs | 2 +- components/templates/src/global_fns/images.rs | 4 ++-- components/templates/src/global_fns/load_data.rs | 2 +- components/utils/src/templates.rs | 2 +- src/cmd/serve.rs | 4 ++-- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/config/src/config/mod.rs b/components/config/src/config/mod.rs index 2bc30ecd9b..b8deb6c44f 100644 --- a/components/config/src/config/mod.rs +++ b/components/config/src/config/mod.rs @@ -19,7 +19,7 @@ use utils::globs::build_ignore_glob_set; use utils::slugs::slugify_paths; // We want a default base url for tests -static DEFAULT_BASE_URL: &str = "http://a-website.com"; +const DEFAULT_BASE_URL: &str = "http://a-website.com"; #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] diff --git a/components/content/src/front_matter/section.rs b/components/content/src/front_matter/section.rs index 76c51461c2..bed9cd0758 100644 --- a/components/content/src/front_matter/section.rs +++ b/components/content/src/front_matter/section.rs @@ -8,7 +8,7 @@ use utils::types::InsertAnchor; use crate::front_matter::split::RawFrontMatter; use crate::SortBy; -static DEFAULT_PAGINATE_PATH: &str = "page"; +const DEFAULT_PAGINATE_PATH: &str = "page"; /// The front matter of every section #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/components/imageproc/src/processor.rs b/components/imageproc/src/processor.rs index 577aeb1f3e..8cf2ef59ff 100644 --- a/components/imageproc/src/processor.rs +++ b/components/imageproc/src/processor.rs @@ -18,7 +18,7 @@ use crate::format::Format; use crate::helpers::get_processed_filename; use crate::{fix_orientation, ImageMeta, ResizeInstructions, ResizeOperation}; -pub static RESIZED_SUBDIR: &str = "processed_images"; +pub const RESIZED_SUBDIR: &str = "processed_images"; /// Holds all data needed to perform a resize operation #[derive(Debug, PartialEq, Eq, Hash)] diff --git a/components/imageproc/tests/resize_image.rs b/components/imageproc/tests/resize_image.rs index 41114abf50..9ec17362ce 100644 --- a/components/imageproc/tests/resize_image.rs +++ b/components/imageproc/tests/resize_image.rs @@ -16,7 +16,7 @@ fn assert_processed_path_matches(path: &str, prefix: &str, extension: &str) { assert!(filename.ends_with(&suffix), "Path `{}` doesn't end with `{}`", path, suffix); } -static CONFIG: &str = r#" +const CONFIG: &str = r#" title = "imageproc integration tests" base_url = "https://example.com" compile_sass = false diff --git a/components/markdown/benches/all.rs b/components/markdown/benches/all.rs index 5b4f915792..393c77483f 100644 --- a/components/markdown/benches/all.rs +++ b/components/markdown/benches/all.rs @@ -8,7 +8,7 @@ use libs::tera::Tera; use markdown::{render_content, RenderContext}; use utils::types::InsertAnchor; -static CONTENT: &str = r#" +const CONTENT: &str = r#" # Modus cognitius profanam ne duae virtutis mundi ## Ut vita diff --git a/components/templates/src/global_fns/images.rs b/components/templates/src/global_fns/images.rs index 2ac74b0ebb..c4541b8221 100644 --- a/components/templates/src/global_fns/images.rs +++ b/components/templates/src/global_fns/images.rs @@ -26,8 +26,8 @@ impl ResizeImage { } } -static DEFAULT_OP: &str = "fill"; -static DEFAULT_FMT: &str = "auto"; +const DEFAULT_OP: &str = "fill"; +const DEFAULT_FMT: &str = "auto"; impl TeraFn for ResizeImage { fn call(&self, args: &HashMap) -> Result { diff --git a/components/templates/src/global_fns/load_data.rs b/components/templates/src/global_fns/load_data.rs index c719495f70..ac52be0796 100644 --- a/components/templates/src/global_fns/load_data.rs +++ b/components/templates/src/global_fns/load_data.rs @@ -18,7 +18,7 @@ use utils::fs::{get_file_time, read_file}; use crate::global_fns::helpers::search_for_file; -static GET_DATA_ARGUMENT_ERROR_MESSAGE: &str = +const GET_DATA_ARGUMENT_ERROR_MESSAGE: &str = "`load_data`: requires EITHER a `path`, `url`, or `literal` argument"; #[derive(Debug, PartialEq, Clone, Copy, Hash)] diff --git a/components/utils/src/templates.rs b/components/utils/src/templates.rs index b51206bac5..a70780dcf8 100644 --- a/components/utils/src/templates.rs +++ b/components/utils/src/templates.rs @@ -4,7 +4,7 @@ use libs::tera::{Context, Tera}; use errors::{bail, Result}; -static DEFAULT_TPL: &str = include_str!("default_tpl.html"); +const DEFAULT_TPL: &str = include_str!("default_tpl.html"); macro_rules! render_default_tpl { ($filename: expr, $url: expr) => {{ diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index eb2b75dd26..84b8b9c8a0 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -61,8 +61,8 @@ enum WatchMode { Condition(bool), } -static METHOD_NOT_ALLOWED_TEXT: &[u8] = b"Method Not Allowed"; -static NOT_FOUND_TEXT: &[u8] = b"Not Found"; +const METHOD_NOT_ALLOWED_TEXT: &[u8] = b"Method Not Allowed"; +const NOT_FOUND_TEXT: &[u8] = b"Not Found"; // This is dist/livereload.min.js from the LiveReload.js v3.2.4 release const LIVE_RELOAD: &str = include_str!("livereload.js");