HighlightingAssets: Move out fn get_integrated_*set() to module scope

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.
This commit is contained in:
Martin Nordholts 2021-07-22 10:28:39 +02:00
parent b040efff79
commit 1bac3750df
1 changed files with 11 additions and 14 deletions

View File

@ -54,7 +54,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(),
@ -83,7 +83,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");
@ -109,19 +109,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<()> {
@ -327,6 +316,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(|| {