on master help sign in
HighlightingAssets: Introduce private fn new() helper
f6fc826Martin Nordholts
src/assets.rs+19−17
@@ -41,6 +41,14 @@ const IGNORED_SUFFIXES: [&str; 10] = [
41];
41];
42
42
43impl HighlightingAssets {
43impl HighlightingAssets {
44+ fn new(syntax_set: SyntaxSet, theme_set: ThemeSet) -> Self {
45+ HighlightingAssets {
46+ syntax_set,
47+ theme_set,
48+ fallback_theme: None,
49+ }
50+ }
51+
44 pub fn default_theme() -> &'static str {
52 pub fn default_theme() -> &'static str {
45 "Monokai Extended"
53 "Monokai Extended"
46 }
54 }
@@ -89,19 +97,17 @@ impl HighlightingAssets {
89 );
97 );
90 }
98 }
91
99
92− Ok(HighlightingAssets {
100+ Ok(HighlightingAssets::new(
93− syntax_set: syntax_set_builder.build(),
101+ syntax_set_builder.build(),
94 theme_set,
102 theme_set,
95− fallback_theme: None,
96− })
103+ ))
97 }
104 }
98
105
99 pub fn from_cache(cache_path: &Path) -> Result<Self> {
106 pub fn from_cache(cache_path: &Path) -> Result<Self> {
100− Ok(HighlightingAssets {
107+ Ok(HighlightingAssets::new(
101− syntax_set: asset_from_cache(&cache_path.join("syntaxes.bin"), "syntax set")?,
108+ asset_from_cache(&cache_path.join("syntaxes.bin"), "syntax set")?,
102− theme_set: asset_from_cache(&cache_path.join("themes.bin"), "theme set")?,
109+ asset_from_cache(&cache_path.join("themes.bin"), "theme set")?,
103− fallback_theme: None,
104− })
110+ ))
105 }
111 }
106
112
107 fn get_integrated_syntaxset() -> SyntaxSet {
113 fn get_integrated_syntaxset() -> SyntaxSet {
@@ -113,14 +119,10 @@ impl HighlightingAssets {
113 }
119 }
114
120
115 pub fn from_binary() -> Self {
121 pub fn from_binary() -> Self {
122+ HighlightingAssets::new(
116− let syntax_set = Self::get_integrated_syntaxset();
123+ Self::get_integrated_syntaxset(),
117− let theme_set = Self::get_integrated_themeset();
124+ Self::get_integrated_themeset(),
118−
125+ )
119− HighlightingAssets {
120− syntax_set,
121− theme_set,
122− fallback_theme: None,
123− }
124 }
126 }
125
127
126 pub fn save_to_cache(&self, target_dir: &Path, current_version: &str) -> Result<()> {
128 pub fn save_to_cache(&self, target_dir: &Path, current_version: &str) -> Result<()> {