Skip to content

Commit

Permalink
HighlightingAssets: Move out fn get_integrated_*set() to module scope
Browse files Browse the repository at this point in the history
They are just a way to get access to data embedded in the binary, so they don't
conceptually belong inside HighlightingAssets.

This has the nice side effect of getting HighlightingAssets::from_cache() and
::from_binary(), that are highly related, next to each other.
  • Loading branch information
Enselic committed Jul 22, 2021
1 parent f6fc826 commit 8ebadc3
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl HighlightingAssets {

pub fn from_files(source_dir: &Path, include_integrated_assets: bool) -> Result<Self> {
let mut theme_set = if include_integrated_assets {
Self::get_integrated_themeset()
get_integrated_themeset()
} else {
ThemeSet {
themes: BTreeMap::new(),
Expand Down Expand Up @@ -84,7 +84,7 @@ impl HighlightingAssets {
builder.add_plain_text_syntax();
builder
} else {
Self::get_integrated_syntaxset().into_builder()
get_integrated_syntaxset().into_builder()
};

let syntax_dir = source_dir.join("syntaxes");
Expand All @@ -110,19 +110,8 @@ impl HighlightingAssets {
))
}

fn get_integrated_syntaxset() -> SyntaxSet {
from_binary(include_bytes!("../assets/syntaxes.bin"))
}

fn get_integrated_themeset() -> ThemeSet {
from_binary(include_bytes!("../assets/themes.bin"))
}

pub fn from_binary() -> Self {
HighlightingAssets::new(
Self::get_integrated_syntaxset(),
Self::get_integrated_themeset(),
)
HighlightingAssets::new(get_integrated_syntaxset(), get_integrated_themeset())
}

pub fn save_to_cache(&self, target_dir: &Path, current_version: &str) -> Result<()> {
Expand Down Expand Up @@ -284,6 +273,14 @@ impl HighlightingAssets {
}
}

fn get_integrated_syntaxset() -> SyntaxSet {
from_binary(include_bytes!("../assets/syntaxes.bin"))
}

fn get_integrated_themeset() -> ThemeSet {
from_binary(include_bytes!("../assets/themes.bin"))
}

fn asset_to_cache<T: serde::Serialize>(asset: &T, path: &Path, description: &str) -> Result<()> {
print!("Writing {} to {} ... ", description, path.to_string_lossy());
dump_to_file(asset, &path).chain_err(|| {
Expand Down

0 comments on commit 8ebadc3

Please sign in to comment.