From b969c01b282287b44c3e131f8c0c53dcbb304e30 Mon Sep 17 00:00:00 2001 From: Abdul-Rahman Sibahi Date: Thu, 31 Oct 2024 14:52:11 +0300 Subject: Replace `once_cell`'s `Lazy` as much as possible (#4617) Co-authored-by: Laurenz --- crates/typst-cli/Cargo.toml | 1 - crates/typst-cli/src/main.rs | 4 ++-- crates/typst-cli/src/world.rs | 7 +++---- 3 files changed, 5 insertions(+), 7 deletions(-) (limited to 'crates/typst-cli') diff --git a/crates/typst-cli/Cargo.toml b/crates/typst-cli/Cargo.toml index 855d7bee..2ecade54 100644 --- a/crates/typst-cli/Cargo.toml +++ b/crates/typst-cli/Cargo.toml @@ -36,7 +36,6 @@ ecow = { workspace = true } fs_extra = { workspace = true } native-tls = { workspace = true } notify = { workspace = true } -once_cell = { workspace = true } open = { workspace = true } parking_lot = { workspace = true } pathdiff = { workspace = true } diff --git a/crates/typst-cli/src/main.rs b/crates/typst-cli/src/main.rs index 464ad624..631befe5 100644 --- a/crates/typst-cli/src/main.rs +++ b/crates/typst-cli/src/main.rs @@ -16,12 +16,12 @@ mod world; use std::cell::Cell; use std::io::{self, Write}; use std::process::ExitCode; +use std::sync::LazyLock; use clap::error::ErrorKind; use clap::Parser; use codespan_reporting::term; use codespan_reporting::term::termcolor::WriteColor; -use once_cell::sync::Lazy; use typst::diag::HintedStrResult; use crate::args::{CliArguments, Command}; @@ -33,7 +33,7 @@ thread_local! { } /// The parsed command line arguments. -static ARGS: Lazy = Lazy::new(|| { +static ARGS: LazyLock = LazyLock::new(|| { CliArguments::try_parse().unwrap_or_else(|error| { if error.kind() == ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand { crate::greet::greet(); diff --git a/crates/typst-cli/src/world.rs b/crates/typst-cli/src/world.rs index b790f41a..f3597544 100644 --- a/crates/typst-cli/src/world.rs +++ b/crates/typst-cli/src/world.rs @@ -1,12 +1,11 @@ use std::collections::HashMap; use std::io::Read; use std::path::{Path, PathBuf}; -use std::sync::OnceLock; +use std::sync::{LazyLock, OnceLock}; use std::{fmt, fs, io, mem}; use chrono::{DateTime, Datelike, FixedOffset, Local, Utc}; use ecow::{eco_format, EcoString}; -use once_cell::sync::Lazy; use parking_lot::Mutex; use typst::diag::{FileError, FileResult}; use typst::foundations::{Bytes, Datetime, Dict, IntoValue}; @@ -25,8 +24,8 @@ use crate::package; /// Static `FileId` allocated for stdin. /// This is to ensure that a file is read in the correct way. -static STDIN_ID: Lazy = - Lazy::new(|| FileId::new_fake(VirtualPath::new(""))); +static STDIN_ID: LazyLock = + LazyLock::new(|| FileId::new_fake(VirtualPath::new(""))); /// A world that provides access to the operating system. pub struct SystemWorld { -- cgit v1.2.3