Skip to content

Commit 651a44e

Browse files
committed
Replace lazy_static with LazyLock
1 parent 6fa830f commit 651a44e

File tree

15 files changed

+45
-71
lines changed

15 files changed

+45
-71
lines changed

Cargo.lock

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ crossbeam-channel = "0.5.13"
3434
crossterm = "0.27.0"
3535
git2 = { version = "0.18.3", default-features = false, features = [] }
3636
if_chain = "1.0.2"
37-
lazy_static = "1.4.0"
3837
num-format = "0.4.4"
3938
parking_lot = "0.12.3"
4039
pico-args = "0.5.0"

src/components/choice.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#[cfg(test)]
22
mod tests;
33

4-
use std::collections::HashMap;
5-
6-
use lazy_static::lazy_static;
4+
use std::{collections::HashMap, sync::LazyLock};
75

86
use crate::{
97
display::DisplayColor,
@@ -12,9 +10,8 @@ use crate::{
1210
view::{LineSegment, ViewData, ViewLine},
1311
};
1412

15-
lazy_static! {
16-
pub(crate) static ref INPUT_OPTIONS: InputOptions = InputOptions::RESIZE | InputOptions::MOVEMENT;
17-
}
13+
pub(crate) static INPUT_OPTIONS: LazyLock<InputOptions> =
14+
LazyLock::new(|| InputOptions::RESIZE | InputOptions::MOVEMENT);
1815

1916
pub(crate) struct Choice<T> {
2017
map: HashMap<char, T>,

src/components/confirm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ mod confirmed;
22
#[cfg(test)]
33
mod tests;
44

5+
use std::sync::LazyLock;
6+
57
use captur::capture;
6-
use lazy_static::lazy_static;
78

89
pub(crate) use self::confirmed::Confirmed;
910
use crate::{
1011
input::{Event, InputOptions, KeyBindings, KeyCode, KeyEvent, StandardEvent},
1112
view::{ViewData, ViewLine},
1213
};
1314

14-
lazy_static! {
15-
pub(crate) static ref INPUT_OPTIONS: InputOptions = InputOptions::RESIZE | InputOptions::MOVEMENT;
16-
}
15+
pub(crate) static INPUT_OPTIONS: LazyLock<InputOptions> =
16+
LazyLock::new(|| InputOptions::RESIZE | InputOptions::MOVEMENT);
1717

1818
pub(crate) struct Confirm {
1919
view_data: ViewData,

src/components/edit.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(test)]
22
mod tests;
33

4-
use lazy_static::lazy_static;
4+
use std::sync::LazyLock;
55

66
use crate::{
77
components::shared::EditableLine,
@@ -10,9 +10,7 @@ use crate::{
1010
view::{LineSegment, LineSegmentOptions, ViewData, ViewDataUpdater, ViewLine},
1111
};
1212

13-
lazy_static! {
14-
pub(crate) static ref INPUT_OPTIONS: InputOptions = InputOptions::RESIZE;
15-
}
13+
pub(crate) static INPUT_OPTIONS: LazyLock<InputOptions> = LazyLock::new(|| InputOptions::RESIZE);
1614

1715
const FINISH_EVENT: Event = Event::Key(KeyEvent {
1816
code: KeyCode::Enter,

src/git/commit_diff_loader.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
use std::{path::PathBuf, sync::Arc};
1+
use std::{
2+
path::PathBuf,
3+
sync::{Arc, LazyLock},
4+
};
25

36
use git2::{DiffFindOptions, DiffOptions, Oid, Repository};
4-
use lazy_static::lazy_static;
57
use parking_lot::{Mutex, MutexGuard};
68

79
use crate::git::{
@@ -16,9 +18,7 @@ use crate::git::{
1618
Status,
1719
};
1820

19-
lazy_static! {
20-
static ref UNKNOWN_PATH: PathBuf = PathBuf::from("unknown");
21-
}
21+
static UNKNOWN_PATH: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("unknown"));
2222

2323
pub(crate) struct CommitDiffLoader<'options> {
2424
config: &'options CommitDiffLoaderOptions,

src/input/event_provider.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,14 @@ pub(crate) fn read_event() -> Result<Option<Event>> {
4747

4848
#[cfg(test)]
4949
mod read_event_mocks {
50-
use std::{io::Result, mem, time::Duration};
50+
use std::{io::Result, mem, sync::LazyLock, time::Duration};
5151

5252
use crossterm::event::{Event, KeyCode, KeyEvent};
53-
use lazy_static::lazy_static;
5453
use parking_lot::Mutex;
5554

56-
lazy_static! {
57-
pub(crate) static ref HAS_POLLED_EVENT: Mutex<Result<bool>> = Mutex::new(Ok(true));
58-
pub(crate) static ref NEXT_EVENT: Mutex<Result<Event>> =
59-
Mutex::new(Ok(Event::Key(KeyEvent::from(KeyCode::Null))));
60-
}
55+
pub(crate) static HAS_POLLED_EVENT: LazyLock<Mutex<Result<bool>>> = LazyLock::new(|| Mutex::new(Ok(true)));
56+
pub(crate) static NEXT_EVENT: LazyLock<Mutex<Result<Event>>> =
57+
LazyLock::new(|| Mutex::new(Ok(Event::Key(KeyEvent::from(KeyCode::Null)))));
6158

6259
pub(crate) fn poll(_: Duration) -> Result<bool> {
6360
let mut lock = HAS_POLLED_EVENT.lock();

src/module.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ mod state;
66
#[cfg(test)]
77
mod tests;
88

9+
use std::sync::LazyLock;
10+
911
use anyhow::Error;
10-
use lazy_static::lazy_static;
1112

1213
pub(crate) use self::{
1314
exit_status::ExitStatus,
@@ -22,10 +23,8 @@ use crate::{
2223
view::{RenderContext, ViewData},
2324
};
2425

25-
lazy_static! {
26-
pub(crate) static ref DEFAULT_INPUT_OPTIONS: InputOptions = InputOptions::RESIZE;
27-
pub(crate) static ref DEFAULT_VIEW_DATA: ViewData = ViewData::new(|_| {});
28-
}
26+
pub(crate) static DEFAULT_INPUT_OPTIONS: LazyLock<InputOptions> = LazyLock::new(|| InputOptions::RESIZE);
27+
pub(crate) static DEFAULT_VIEW_DATA: LazyLock<ViewData> = LazyLock::new(|| ViewData::new(|_| {}));
2928

3029
pub(crate) trait Module: Send {
3130
fn activate(&mut self, _previous_state: State) -> Results {

src/modules/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
use std::sync::LazyLock;
2+
13
use captur::capture;
2-
use lazy_static::lazy_static;
34

45
use crate::{
56
display::DisplayColor,
@@ -11,9 +12,8 @@ use crate::{
1112
view::{LineSegment, RenderContext, ViewData, ViewLine},
1213
};
1314

14-
lazy_static! {
15-
pub(crate) static ref INPUT_OPTIONS: InputOptions = InputOptions::RESIZE | InputOptions::MOVEMENT;
16-
}
15+
pub(crate) static INPUT_OPTIONS: LazyLock<InputOptions> =
16+
LazyLock::new(|| InputOptions::RESIZE | InputOptions::MOVEMENT);
1717

1818
pub(crate) struct Error {
1919
return_state: State,

src/modules/external_editor.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ mod external_editor_state;
55
#[cfg(all(unix, test))]
66
mod tests;
77

8-
use std::sync::Arc;
8+
use std::sync::{Arc, LazyLock};
99

1010
use anyhow::{anyhow, Result};
11-
use lazy_static::lazy_static;
1211
use parking_lot::Mutex;
1312

1413
use self::{action::Action, argument_tokenizer::tokenize, external_editor_state::ExternalEditorState};
@@ -21,9 +20,7 @@ use crate::{
2120
view::{RenderContext, ViewData, ViewLine},
2221
};
2322

24-
lazy_static! {
25-
static ref INPUT_OPTIONS: InputOptions = InputOptions::RESIZE;
26-
}
23+
static INPUT_OPTIONS: LazyLock<InputOptions> = LazyLock::new(|| InputOptions::RESIZE);
2724

2825
pub(crate) struct ExternalEditor {
2926
editor: String,

0 commit comments

Comments
 (0)