on master help sign in
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.

commitdd0925a9465978bdd4aef0da45a6f323b6d10774 authorMartin Nordholts <enselic@gmail.com> dateMon 22 Nov 2021, 20:59 (5 years ago) parentd7671fa
3 files changed+6−6
Cargo.lock+1−1 Cargo.toml+1−1 src/assets.rs+4−4
Cargo.lock+1−1
@@ -102,8 +102,8 @@ dependencies = [
102102 "globset",
103103 "grep-cli",
104104 "lazy_static",
105− "lazycell",
106105 "nix",
106+ "once_cell",
107107 "path_abs",
108108 "predicates",
109109 "semver",
Cargo.toml+1−1
@@ -49,7 +49,7 @@ bincode = "1.0"
4949console = "0.15.0"
5050flate2 = "1.0"
5151lazy_static = { version = "1.4", optional = true }
52−lazycell = "1.0"
52+once_cell = "1.8"
5353thiserror = "1.0"
5454wild = { version = "2.0", optional = true }
5555content_inspector = "0.2.4"
src/assets.rs+4−4
@@ -2,7 +2,7 @@ use std::ffi::OsStr;
22use std::fs;
33use std::path::Path;
44
5−use lazycell::LazyCell;
5+use once_cell::unsync::OnceCell;
66
77use syntect::highlighting::{Theme, ThemeSet};
88use syntect::parsing::{SyntaxReference, SyntaxSet};
@@ -27,7 +27,7 @@ mod serialized_syntax_set;
2727
2828#[derive(Debug)]
2929pub struct HighlightingAssets {
30− syntax_set_cell: LazyCell<SyntaxSet>,
30+ syntax_set_cell: OnceCell<SyntaxSet>,
3131 serialized_syntax_set: SerializedSyntaxSet,
3232
3333 theme_set: ThemeSet,
@@ -49,7 +49,7 @@ pub(crate) const COMPRESS_THEMES: bool = true;
4949impl HighlightingAssets {
5050 fn new(serialized_syntax_set: SerializedSyntaxSet, theme_set: ThemeSet) -> Self {
5151 HighlightingAssets {
52− syntax_set_cell: LazyCell::new(),
52+ syntax_set_cell: OnceCell::new(),
5353 serialized_syntax_set,
5454 theme_set,
5555 fallback_theme: None,
@@ -80,7 +80,7 @@ impl HighlightingAssets {
8080
8181 fn get_syntax_set(&self) -> Result<&SyntaxSet> {
8282 self.syntax_set_cell
83− .try_borrow_with(|| self.serialized_syntax_set.deserialize())
83+ .get_or_try_init(|| self.serialized_syntax_set.deserialize())
8484 }
8585
8686 /// Use [Self::get_syntaxes] instead