Skip to content

Commit

Permalink
Use new type pattern instead of enum with one variant
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Jan 22, 2022
1 parent 9c2b737 commit 3d01991
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl HighlightingAssets {
HighlightingAssets {
syntax_set_cell: OnceCell::new(),
serialized_syntax_set,
theme_set: ThemeSet::LazyThemeSet(theme_set),
theme_set: ThemeSet(theme_set),
fallback_theme: None,
}
}
Expand Down
12 changes: 3 additions & 9 deletions src/assets/theme_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,16 @@ use super::lazy_theme_set::LazyThemeSet;
/// A collection of syntect themes, similar to [`syntect::highlighting::ThemeSet`].
/// The themes are deserialized on-demand only.
#[derive(Debug)]
pub enum ThemeSet {
LazyThemeSet(LazyThemeSet),
}
pub struct ThemeSet(pub LazyThemeSet);

impl ThemeSet {
/// Look up a theme by name
pub fn get(&self, name: &str) -> Option<&syntect::highlighting::Theme> {
match self {
ThemeSet::LazyThemeSet(lazy_theme_set) => lazy_theme_set.get(name),
}
self.0.get(name)
}

/// An iterator over all theme names
pub fn theme_names(&self) -> impl Iterator<Item = &str> {
match self {
ThemeSet::LazyThemeSet(lazy_theme_set) => lazy_theme_set.themes(),
}
self.0.themes()
}
}

0 comments on commit 3d01991

Please sign in to comment.