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.
This commit is contained in:
Martin Nordholts 2021-11-22 20:59:28 +01:00
parent d7671fa8e3
commit dd0925a946
3 changed files with 6 additions and 6 deletions

2
Cargo.lock generated
View File

@ -102,8 +102,8 @@ dependencies = [
"globset",
"grep-cli",
"lazy_static",
"lazycell",
"nix",
"once_cell",
"path_abs",
"predicates",
"semver",

View File

@ -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"

View File

@ -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<SyntaxSet>,
syntax_set_cell: OnceCell<SyntaxSet>,
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