From 4c169f142f39a892f77eda99b1c710366ffe1473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=94=20=C7=80=20=CE=9E=20=C8=BC?= Date: Mon, 2 Oct 2023 23:26:42 +0100 Subject: [PATCH 1/2] Removal of lazy_static --- Cargo.toml | 1 - src/main.rs | 27 ++++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c828649..bd4e00f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ path = "src/main.rs" name = "bookmark-cd" [dependencies] -lazy_static = "1.4.0" clap = { version = "4.4", features = ["derive"] } csv = "1.2" home = "0.5.5" diff --git a/src/main.rs b/src/main.rs index 8deae1a..fc6a274 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,15 @@ use clap::Parser; use csv::{Reader, Result, Writer}; use home::home_dir; -use lazy_static::lazy_static; -use std::env; -use std::path::Path; -use std::process::exit; -use std::{collections::BTreeMap, env::current_dir}; +use std::{ + collections::BTreeMap, + env, + env::current_dir, + path::Path, + process::exit, + sync::OnceLock, +}; + use tabled::{ builder::Builder, settings::object::Segment, settings::Alignment, settings::Modify, settings::Style, @@ -34,12 +38,13 @@ fn main() { let options = cli::Options::parse(); - lazy_static! { - static ref DESCRIPTION: String = format!( + static DESCRIPTION: OnceLock = OnceLock::new(); + DESCRIPTION.get_or_init(|| { + format!( "bcd {}: bookmark directories and move to them.", env!("CARGO_PKG_VERSION") - ); - }; + ) + }); if options.install { // a way to try to set up the shell when the data file exists but the `bcd` function is not. @@ -51,7 +56,7 @@ fn main() { } if options.version { - println!("{}", DESCRIPTION.as_str()); + println!("{}", DESCRIPTION.get().unwrap().as_str()); exit(0); } @@ -158,7 +163,7 @@ fn main() { exit(0); } - println!("{}", DESCRIPTION.as_str()); + println!("{}", DESCRIPTION.get().unwrap().as_str()); } } From 296178d9cb2ef56749d872a59003a7362e072c97 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 22:27:10 +0000 Subject: [PATCH 2/2] Format Rust code using rustfmt --- src/main.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index fc6a274..494aa18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,12 +2,7 @@ use clap::Parser; use csv::{Reader, Result, Writer}; use home::home_dir; use std::{ - collections::BTreeMap, - env, - env::current_dir, - path::Path, - process::exit, - sync::OnceLock, + collections::BTreeMap, env, env::current_dir, path::Path, process::exit, sync::OnceLock, }; use tabled::{