Skip to content

Commit

Permalink
refactor: replace format! with concat! for string literals (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Integral-Tech authored Dec 8, 2024
1 parent 83e3223 commit 9728a13
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/args/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ mod tests {
fn test_matches() {
let args = Args::default();
let matches = ArgMatches::new(&args);
let key = format!("{}_general_test", env!("CARGO_PKG_NAME")).to_uppercase();
let key = concat!(env!("CARGO_PKG_NAME"), "_general_test").to_uppercase();
env::set_var(&key, "...");
assert_eq!("...", matches.get_env("test").unwrap_or_default());
assert_eq!(Some("..."), matches.value_of("test"));
Expand Down
8 changes: 2 additions & 6 deletions src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ use std::ffi::OsStr;
use std::fs;
use std::path::{Path, PathBuf};

/* Extension of the configuration file */
const CONFIG_FILE_EXTENSION: &str = "conf";

/* Representation of the output file */
#[derive(Debug)]
pub struct File {
Expand Down Expand Up @@ -85,13 +82,12 @@ impl File {
*/
pub fn get_config_file() -> Option<PathBuf> {
if let Ok(config_file) =
env::var(format!("{}_CONFIG", env!("CARGO_PKG_NAME")).to_uppercase())
env::var(concat!(env!("CARGO_PKG_NAME"), "_CONFIG").to_uppercase())
{
return Some(PathBuf::from(config_file));
}
if let Some(config_dir) = dirs::config_dir() {
let file_name =
format!("{}.{}", env!("CARGO_PKG_NAME"), CONFIG_FILE_EXTENSION);
let file_name = concat!(env!("CARGO_PKG_NAME"), ".conf");
for config_file in [
config_dir.join(&file_name),

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 92 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits
config_dir.join(env!("CARGO_PKG_NAME")).join(&file_name),

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win32-msvc)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (linux-musl)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-gnu)

the borrowed expression implements the required traits

Check failure on line 93 in src/file/mod.rs

View workflow job for this annotation

GitHub Actions / Test (win-msvc)

the borrowed expression implements the required traits
Expand Down
2 changes: 1 addition & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ mod tests {
let matches = ArgMatches::new(&args);
let mut settings = AppSettings::new(&matches);
env::set_var(
format!("{}_general_color", env!("CARGO_PKG_NAME")).to_uppercase(),
concat!(env!("CARGO_PKG_NAME"), "_general_color").to_uppercase(),
"d473d4",
);
assert_eq!(
Expand Down
4 changes: 2 additions & 2 deletions src/util/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<'a> Logger<'a> {
.level(self.level_filter);
if self.settings.save.file.format.is_animation() {
logger = logger.level_for(
format!("{}::edit", env!("CARGO_PKG_NAME")),
concat!(env!("CARGO_PKG_NAME"), "::edit"),
LevelFilter::Warn,
)
}
Expand All @@ -95,7 +95,7 @@ mod tests {
#[test]
fn test_logger() -> Result<(), SetLoggerError> {
let quiet_var =
format!("{}_GENERAL_QUIET", env!("CARGO_PKG_NAME").to_uppercase());
concat!(env!("CARGO_PKG_NAME"), "_GENERAL_QUIET").to_uppercase();
env::set_var(quiet_var, "true");
let args = Args::default();
let matches = ArgMatches::new(&args);
Expand Down
3 changes: 2 additions & 1 deletion src/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ unsafe extern "C" fn handle_x11_errors(
{
CStr::from_ptr(error_text.as_mut_ptr() as *mut c_char)
.to_string_lossy()
.into_owned() + " "
.into_owned()
+ " "
} else {
String::from("Unknown error ")
},
Expand Down

0 comments on commit 9728a13

Please sign in to comment.