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

commit1bac3750dfe5dbd4d54894717478e67d0dba4d83 authorMartin Nordholts <enselic@gmail.com> dateThu 22 Jul 2021, 10:28 (5 years ago) parentb040eff
1 file changed+11−14
src/assets.rs+11−14
src/assets.rs+11−14
@@ -54,7 +54,7 @@ impl HighlightingAssets {
5454
5555 pub fn from_files(source_dir: &Path, include_integrated_assets: bool) -> Result<Self> {
5656 let mut theme_set = if include_integrated_assets {
57− Self::get_integrated_themeset()
57+ get_integrated_themeset()
5858 } else {
5959 ThemeSet {
6060 themes: BTreeMap::new(),
@@ -83,7 +83,7 @@ impl HighlightingAssets {
8383 builder.add_plain_text_syntax();
8484 builder
8585 } else {
86− Self::get_integrated_syntaxset().into_builder()
86+ get_integrated_syntaxset().into_builder()
8787 };
8888
8989 let syntax_dir = source_dir.join("syntaxes");
@@ -109,19 +109,8 @@ impl HighlightingAssets {
109109 ))
110110 }
111111
112− fn get_integrated_syntaxset() -> SyntaxSet {
113− from_binary(include_bytes!("../assets/syntaxes.bin"))
114− }
115−
116− fn get_integrated_themeset() -> ThemeSet {
117− from_binary(include_bytes!("../assets/themes.bin"))
118− }
119−
120112 pub fn from_binary() -> Self {
121− HighlightingAssets::new(
122− Self::get_integrated_syntaxset(),
123− Self::get_integrated_themeset(),
124− )
113+ HighlightingAssets::new(get_integrated_syntaxset(), get_integrated_themeset())
125114 }
126115
127116 pub fn save_to_cache(&self, target_dir: &Path, current_version: &str) -> Result<()> {
@@ -327,6 +316,14 @@ impl HighlightingAssets {
327316 }
328317}
329318
319+fn get_integrated_syntaxset() -> SyntaxSet {
320+ from_binary(include_bytes!("../assets/syntaxes.bin"))
321+}
322+
323+fn get_integrated_themeset() -> ThemeSet {
324+ from_binary(include_bytes!("../assets/themes.bin"))
325+}
326+
330327fn asset_to_cache<T: serde::Serialize>(asset: &T, path: &Path, description: &str) -> Result<()> {
331328 print!("Writing {} to {} ... ", description, path.to_string_lossy());
332329 dump_to_file(asset, &path).chain_err(|| {