Skip to content

Commit

Permalink
Replace lazycell with once_cell
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Enselic committed Nov 22, 2021
1 parent d7671fa commit dd0925a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dd0925a

Please sign in to comment.