Skip to content

Commit

Permalink
Swap out lazy_static for std::sync::LazyLock
Browse files Browse the repository at this point in the history
  • Loading branch information
robbert-vdh committed Aug 18, 2024
1 parent 3171178 commit 61c79ab
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ Since there is no stable release yet, the changes are organized per day in
reverse chronological order. The main purpose of this document in its current
state is to list breaking changes.

## [2024-08-18]

### Breaking changes

- The minimum supported Rust version has been bumped to 1.80 to replace the last
uses of `lazy_static` with `std::sync::LazyLock`.

## [2024-05-05]

### Breaking changes
Expand Down
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "nih_plug"
version = "0.0.0"
edition = "2021"
rust-version = "1.70"
rust-version = "1.80"
authors = ["Robbert van der Helm <[email protected]>"]
license = "ISC"

Expand Down Expand Up @@ -85,7 +85,6 @@ cfg-if = "1.0"
# This supports CLAP 1.1.8
clap-sys = { git = "https://github.com/robbert-vdh/clap-sys.git", branch = "feature/cstr-macro" }
crossbeam = "0.8"
lazy_static = "1.4"
log = { version = "0.4", features = ["std", "release_max_level_info"] }
midi-consts = "0.1"
nih_log = "0.3.1"
Expand Down
1 change: 0 additions & 1 deletion nih_plug_egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ raw-window-handle = "0.5"
baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "45465c5f46abed6c6ce370fffde5edc8e4cd5aa3" }
crossbeam = "0.8"
egui-baseview = { git = "https://github.com/BillyDM/egui-baseview.git", rev = "68c4d0e8e5c1c702a888a245f4ac50eddfdfcaed", default-features = false }
lazy_static = "1.4"
parking_lot = "0.12"
# To make the state persistable
serde = { version = "1.0", features = ["derive"] }
12 changes: 5 additions & 7 deletions nih_plug_egui/src/widgets/param_slider.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::sync::Arc;
use std::sync::{Arc, LazyLock};

use egui_baseview::egui::{
self, emath, vec2, Key, Response, Sense, Stroke, TextEdit, TextStyle, Ui, Vec2, Widget,
WidgetText,
};
use lazy_static::lazy_static;
use nih_plug::prelude::{Param, ParamSetter};
use parking_lot::Mutex;

Expand All @@ -14,11 +13,10 @@ use super::util;
/// noramlized parameter.
const GRANULAR_DRAG_MULTIPLIER: f32 = 0.0015;

lazy_static! {
static ref DRAG_NORMALIZED_START_VALUE_MEMORY_ID: egui::Id = egui::Id::new((file!(), 0));
static ref DRAG_AMOUNT_MEMORY_ID: egui::Id = egui::Id::new((file!(), 1));
static ref VALUE_ENTRY_MEMORY_ID: egui::Id = egui::Id::new((file!(), 2));
}
static DRAG_NORMALIZED_START_VALUE_MEMORY_ID: LazyLock<egui::Id> =
LazyLock::new(|| egui::Id::new((file!(), 0)));
static DRAG_AMOUNT_MEMORY_ID: LazyLock<egui::Id> = LazyLock::new(|| egui::Id::new((file!(), 1)));
static VALUE_ENTRY_MEMORY_ID: LazyLock<egui::Id> = LazyLock::new(|| egui::Id::new((file!(), 2)));

/// A slider widget similar to [`egui::widgets::Slider`] that knows about NIH-plug parameters ranges
/// and can get values for it. The slider supports double click and control click to reset,
Expand Down
8 changes: 3 additions & 5 deletions src/event_loop/background_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use anymap::Entry;
use crossbeam::channel;
use parking_lot::Mutex;
use std::sync::{Arc, Weak};
use std::sync::{Arc, LazyLock, Weak};
use std::thread::{self, JoinHandle};

use super::MainThreadExecutor;
Expand Down Expand Up @@ -73,10 +73,8 @@ where
// Rust does not allow us to use the `T` and `E` type variable in statics, so this is a
// workaround to have a singleton that also works if for whatever reason there arem ultiple `T`
// and `E`s in a single process (won't happen with normal plugin usage, but sho knwos).
lazy_static::lazy_static! {
static ref HANDLE_MAP: Mutex<anymap::Map<dyn std::any::Any + Send>> =
Mutex::new(anymap::Map::new());
}
static HANDLE_MAP: LazyLock<Mutex<anymap::Map<dyn std::any::Any + Send>>> =
LazyLock::new(|| Mutex::new(anymap::Map::new()));

impl<T: Send + 'static, E: MainThreadExecutor<T> + 'static> WorkerThread<T, E> {
fn spawn() -> Self {
Expand Down
1 change: 0 additions & 1 deletion src/wrapper/clap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub use clap_sys::factory::plugin_factory::{clap_plugin_factory, CLAP_PLUGIN_FAC
pub use clap_sys::host::clap_host;
pub use clap_sys::plugin::{clap_plugin, clap_plugin_descriptor};
pub use clap_sys::version::CLAP_VERSION;
pub use lazy_static::lazy_static;

/// Export one or more CLAP plugins from this library using the provided plugin types.
#[macro_export]
Expand Down

0 comments on commit 61c79ab

Please sign in to comment.