From dd0925a9465978bdd4aef0da45a6f323b6d10774 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Mon, 22 Nov 2021 20:59:28 +0100 Subject: [PATCH] Replace lazycell with once_cell We started to use lazycell because syntect already used it. But syntect has changed to use once_cell. So we should also do that to prepare for using the upcoming version of syntect. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/assets.rs | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e8e60b16..153ed7f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,8 +102,8 @@ dependencies = [ "globset", "grep-cli", "lazy_static", - "lazycell", "nix", + "once_cell", "path_abs", "predicates", "semver", diff --git a/Cargo.toml b/Cargo.toml index 98062b90..539117de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,7 @@ bincode = "1.0" console = "0.15.0" flate2 = "1.0" lazy_static = { version = "1.4", optional = true } -lazycell = "1.0" +once_cell = "1.8" thiserror = "1.0" wild = { version = "2.0", optional = true } content_inspector = "0.2.4" diff --git a/src/assets.rs b/src/assets.rs index 5a285e4c..206664cc 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -2,7 +2,7 @@ use std::ffi::OsStr; use std::fs; use std::path::Path; -use lazycell::LazyCell; +use once_cell::unsync::OnceCell; use syntect::highlighting::{Theme, ThemeSet}; use syntect::parsing::{SyntaxReference, SyntaxSet}; @@ -27,7 +27,7 @@ mod serialized_syntax_set; #[derive(Debug)] pub struct HighlightingAssets { - syntax_set_cell: LazyCell, + syntax_set_cell: OnceCell, serialized_syntax_set: SerializedSyntaxSet, theme_set: ThemeSet, @@ -49,7 +49,7 @@ pub(crate) const COMPRESS_THEMES: bool = true; impl HighlightingAssets { fn new(serialized_syntax_set: SerializedSyntaxSet, theme_set: ThemeSet) -> Self { HighlightingAssets { - syntax_set_cell: LazyCell::new(), + syntax_set_cell: OnceCell::new(), serialized_syntax_set, theme_set, fallback_theme: None, @@ -80,7 +80,7 @@ impl HighlightingAssets { fn get_syntax_set(&self) -> Result<&SyntaxSet> { self.syntax_set_cell - .try_borrow_with(|| self.serialized_syntax_set.deserialize()) + .get_or_try_init(|| self.serialized_syntax_set.deserialize()) } /// Use [Self::get_syntaxes] instead