Skip to content

Commit

Permalink
Rust 1.80: Use std::sync::LazyLock.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Jun 18, 2024
1 parent 103b5b2 commit 7ad4c0e
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ resolver = "2"
# When changing any of these values, be sure to also update the non-workspace packages
# as listed above, if applicable.
edition = "2021"
rust-version = "1.79"
rust-version = "1.80"
license = "MIT OR Apache-2.0"
authors = ["Kevin Reid <[email protected]>"]
# TODO: add homepage = "..." when we have one
Expand Down
4 changes: 2 additions & 2 deletions all-is-cubes-desktop/src/bin/all-is-cubes/command_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
use std::fmt::Write as _;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::LazyLock;
use std::time::Duration;

use clap::builder::{PathBufValueParser, PossibleValue, PossibleValuesParser};
use clap::{builder::TypedValueParser, Parser, ValueEnum};
use once_cell::sync::Lazy;
use strum::IntoEnumIterator;

use all_is_cubes::camera;
Expand Down Expand Up @@ -210,7 +210,7 @@ impl AicDesktopArgs {
/// clap doesn't automatically compile the possible value help
/// (<https://github.com/clap-rs/clap/issues/3312>), so do it ourselves.
/// This is in a static so that it can become an `&'static str`.
static GRAPHICS_HELP_LONG: Lazy<String> = Lazy::new(|| {
static GRAPHICS_HELP_LONG: LazyLock<String> = LazyLock::new(|| {
let pv_iter = GraphicsType::value_variants()
.iter()
.filter_map(|v| v.to_possible_value())
Expand Down
6 changes: 3 additions & 3 deletions all-is-cubes-desktop/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Logging. And terminal progress bars. And their cooperation.
use std::collections::HashSet;
use std::sync::LazyLock;

use anyhow::Context as _;
use once_cell::sync::Lazy;

#[cfg(feature = "rerun")]
use all_is_cubes::rerun_glue as rg;
Expand Down Expand Up @@ -185,8 +185,8 @@ fn suspend_indicatif_in<R>(f: impl FnOnce() -> R) -> R {
COOPERATIVE_PROGRESS.suspend(f)
}

pub(crate) static COOPERATIVE_PROGRESS: Lazy<indicatif::MultiProgress> =
Lazy::new(indicatif::MultiProgress::new);
pub(crate) static COOPERATIVE_PROGRESS: LazyLock<indicatif::MultiProgress> =
LazyLock::new(indicatif::MultiProgress::new);

/// Constructs a progress bar which cooperates with logging to share stderr cleanly.
///
Expand Down
4 changes: 2 additions & 2 deletions all-is-cubes-gpu/src/common/reloadable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use std::sync::{Arc, Mutex, PoisonError};
use std::time::Duration;
use std::sync::LazyLock;

use once_cell::sync::Lazy;
use resource::Resource;

use all_is_cubes::listen::{ListenableCell, ListenableSource};
Expand Down Expand Up @@ -65,7 +65,7 @@ fn res_arc_str(r: &Resource<str>) -> Arc<str> {
Arc::from(<Resource<str> as AsRef<str>>::as_ref(r))
}

static POLLED_RELOADABLES: Lazy<Mutex<Vec<Reloadable>>> = Lazy::new(|| {
static POLLED_RELOADABLES: LazyLock<Mutex<Vec<Reloadable>>> = LazyLock::new(|| {
// Spawn a thread to poll for reloading, as soon as anyone cares,
// but only if it's possible and useful.
if cfg!(all(not(target_family = "wasm"), debug_assertions)) {
Expand Down
3 changes: 1 addition & 2 deletions all-is-cubes-gpu/src/in_wgpu/shaders.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! Hot-reloadable shader loading.
use std::borrow::Cow;
use std::sync::Arc;
use std::sync::{Arc, LazyLock as Lazy};
use std::task;

use futures_core::future::BoxFuture;
use once_cell::sync::Lazy;

use all_is_cubes::listen;

Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name = "all-is-cubes-wasm"
version = "0.7.0"
authors = ["Kevin Reid <[email protected]>"]
edition = "2021"
rust-version = "1.79"
rust-version = "1.80"
description = "Web client for the recursive voxel game All is Cubes."
# TODO: add homepage = "..." when we have one
repository = "https://github.com/kpreid/all-is-cubes"
Expand Down
4 changes: 2 additions & 2 deletions all-is-cubes-wasm/src/web_glue.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! DOM and JS environment manipulation that isn't application-specific.
use std::sync::LazyLock;
use std::sync::Mutex;

use futures_core::future::BoxFuture;
use js_sys::{Error, Function};
use once_cell::sync::Lazy;
use wasm_bindgen::prelude::Closure;
use wasm_bindgen::JsCast; // dyn_into()
use web_sys::{AddEventListenerOptions, Document, Element, Event, EventTarget, Text};
Expand Down Expand Up @@ -111,4 +111,4 @@ pub(crate) async fn yield_to_event_loop() {

/// Time used by [`yield_to_event_loop`] to decude whether to actually yield.
/// TODO: A thread-local would be a better expression of intent here.
static NEXT_YIELD_INSTANT: Lazy<Mutex<Instant>> = Lazy::new(|| Mutex::new(Instant::now()));
static NEXT_YIELD_INSTANT: LazyLock<Mutex<Instant>> = LazyLock::new(|| Mutex::new(Instant::now()));
2 changes: 1 addition & 1 deletion all-is-cubes/src/content/load_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub fn load_png_from_bytes(name: &str, bytes: &'static [u8]) -> DecodedPng {
cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
#[doc(hidden)]
pub use ::once_cell::sync::Lazy as LazyForIncludeImage;
pub use ::std::sync::LazyLock as LazyForIncludeImage;

/// Load an image from a relative path. Memoized if the `std` feature is enabled.
#[doc(hidden)]
Expand Down
4 changes: 2 additions & 2 deletions tools/xtask/src/xtask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ use std::io::Write as _;
use std::mem;
use std::path::Path;
use std::path::PathBuf;
use std::sync::LazyLock;
use std::time::Duration;
use std::time::Instant;

use anyhow::Context as _;
use anyhow::Error as ActionError;
use cargo_metadata::PackageId;
use once_cell::sync::Lazy;
use xshell::{cmd, pushd, Cmd, Pushd};

mod fs_ops;
Expand Down Expand Up @@ -835,7 +835,7 @@ enum Features {
/// Path to the main All is Cubes project/repository directory.
///
/// (In the typical case, this will be equal to the current directory.)
static PROJECT_DIR: Lazy<PathBuf> = Lazy::new(|| {
static PROJECT_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
let mut path = PathBuf::from(
std::env::var_os("CARGO_MANIFEST_DIR")
.expect("CARGO_MANIFEST_DIR environment variable not set"),
Expand Down

0 comments on commit 7ad4c0e

Please sign in to comment.