Skip to content

Commit

Permalink
Use once_cell instead of lazy_static
Browse files Browse the repository at this point in the history
This seems to be generally considered the preferred, idiomatic solution
now. This is in the standard library behind a feature flag (apparently
now called `std::sync::LazyLock`).
  • Loading branch information
ids1024 committed Oct 28, 2022
1 parent 8221794 commit d89cfaf
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/todos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ publish = false

[dependencies]
iced = { path = "../..", features = ["async-std", "debug"] }
once_cell = "1.15.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
lazy_static = "1.4"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
async-std = "1.0"
Expand Down
6 changes: 2 additions & 4 deletions examples/todos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ use iced::window;
use iced::{Application, Element};
use iced::{Color, Command, Font, Length, Settings, Subscription};

use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};

lazy_static! {
static ref INPUT_ID: text_input::Id = text_input::Id::unique();
}
static INPUT_ID: Lazy<text_input::Id> = Lazy::new(|| text_input::Id::unique());

pub fn main() -> iced::Result {
Todos::run(Settings {
Expand Down
2 changes: 1 addition & 1 deletion examples/websocket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false
iced = { path = "../..", features = ["tokio", "debug"] }
iced_native = { path = "../../native" }
iced_futures = { path = "../../futures" }
lazy_static = "1.4"
once_cell = "1.15.0"

[dependencies.async-tungstenite]
version = "0.16"
Expand Down
6 changes: 3 additions & 3 deletions examples/websocket/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use iced::widget::{
use iced::{
Application, Color, Command, Element, Length, Settings, Subscription, Theme,
};
use once_cell::sync::Lazy;

pub fn main() -> iced::Result {
WebSocket::run(Settings::default())
Expand Down Expand Up @@ -165,6 +166,5 @@ impl Default for State {
}
}

lazy_static::lazy_static! {
static ref MESSAGE_LOG: scrollable::Id = scrollable::Id::unique();
}
static MESSAGE_LOG: Lazy<scrollable::Id> =
Lazy::new(|| scrollable::Id::unique());
4 changes: 2 additions & 2 deletions style/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ features = ["palette"]
[dependencies.palette]
version = "0.6"

[dependencies.lazy_static]
version = "1.4"
[dependencies.once_cell]
version = "1.15"
11 changes: 5 additions & 6 deletions style/src/theme/palette.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use iced_core::Color;

use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use palette::{FromColor, Hsl, Mix, RelativeContrast, Srgb};

#[derive(Debug, Clone, Copy, PartialEq)]
Expand Down Expand Up @@ -66,11 +66,10 @@ pub struct Extended {
pub danger: Danger,
}

lazy_static! {
pub static ref EXTENDED_LIGHT: Extended =
Extended::generate(Palette::LIGHT);
pub static ref EXTENDED_DARK: Extended = Extended::generate(Palette::DARK);
}
pub static EXTENDED_LIGHT: Lazy<Extended> =
Lazy::new(|| Extended::generate(Palette::LIGHT));
pub static EXTENDED_DARK: Lazy<Extended> =
Lazy::new(|| Extended::generate(Palette::DARK));

impl Extended {
pub fn generate(palette: Palette) -> Self {
Expand Down

0 comments on commit d89cfaf

Please sign in to comment.