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

source

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();
source

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

source§

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

source§

fn from(lazy_themes: &LazyThemeSet) -> Self

Converts to this type from the input type.
source§

impl From<&ThemeSet> for LazyThemeSet

source§

fn from(full_themes: &ThemeSet) -> Self

Converts to this type from the input type.
source§

impl From<EmbeddedLazyThemeSet> for LazyThemeSet

source§

fn from(embedded: EmbeddedLazyThemeSet) -> Self

Converts to this type from the input type.
source§

impl Serialize for LazyThemeSet

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,