Struct two_face::theme::LazyThemeSet
source · pub struct LazyThemeSet { /* private fields */ }
Expand description
A ThemeSet
that lazily deserializes/decompresses a single theme at a time
This pattern is already actually used by syntect::parsing::SyntaxSet
which
deserializes/decompresses syntaxes on demand. Doing this has the benefit of lowering load times
when you’re only using a few themes at the expense of slightly larger embedded size due to
worse compression
§Example
For convenience you can easily convert between a LazyThemeSet
and a ThemeSet
use two_face::theme::{extra, LazyThemeSet};
let theme_set: LazyThemeSet = LazyThemeSet::from(extra());
let syntect_theme_set = syntect::highlighting::ThemeSet::from(&theme_set);
Implementations§
source§impl LazyThemeSet
impl LazyThemeSet
sourcepub fn get(&self, name: &str) -> Option<&Theme>
pub fn get(&self, name: &str) -> Option<&Theme>
Access a single theme from the set
Calling this multiple times for the same theme will only deserialize and decompress the theme once
§Example
use two_face::theme::{extra, LazyThemeSet};
let theme_set = LazyThemeSet::from(extra());
// Loads the theme
let nord1 = theme_set.get("Nord").unwrap();
// Reuses the same loaded theme
let nord2 = theme_set.get("Nord").unwrap();
sourcepub fn theme_names(&self) -> impl Iterator<Item = &str>
pub fn theme_names(&self) -> impl Iterator<Item = &str>
Iterate over all the theme names included in the set
§Example
use two_face::theme::{extra, LazyThemeSet};
let theme_set = LazyThemeSet::from(extra());
// Nord should be included
assert!(theme_set.theme_names().find(|&name| name == "Nord").is_some());
Trait Implementations§
source§impl<'de> Deserialize<'de> for LazyThemeSet
impl<'de> Deserialize<'de> for LazyThemeSet
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl From<&LazyThemeSet> for ThemeSet
impl From<&LazyThemeSet> for ThemeSet
source§fn from(lazy_themes: &LazyThemeSet) -> Self
fn from(lazy_themes: &LazyThemeSet) -> Self
Converts to this type from the input type.
source§impl From<&ThemeSet> for LazyThemeSet
impl From<&ThemeSet> for LazyThemeSet
source§impl From<EmbeddedLazyThemeSet> for LazyThemeSet
impl From<EmbeddedLazyThemeSet> for LazyThemeSet
source§fn from(embedded: EmbeddedLazyThemeSet) -> Self
fn from(embedded: EmbeddedLazyThemeSet) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for LazyThemeSet
impl RefUnwindSafe for LazyThemeSet
impl Send for LazyThemeSet
impl Sync for LazyThemeSet
impl Unpin for LazyThemeSet
impl UnwindSafe for LazyThemeSet
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more