[demo] Make syntect an optional dependency

Adds a whopping 1.4 MB to the WASM
This commit is contained in:
Emil Ernerfeldt 2021-01-31 16:52:26 +01:00
parent 7336df53b7
commit e529bd3ea4
2 changed files with 15 additions and 1 deletions

View file

@ -30,7 +30,7 @@ criterion = { version = "0.3", default-features = false }
[features] [features]
default = [] default = []
http = ["image", "syntect", "epi/http"] http = ["image", "epi/http"]
persistence = ["epi/persistence", "serde"] persistence = ["epi/persistence", "serde"]
[[bench]] [[bench]]

View file

@ -196,6 +196,7 @@ fn ui_resouce(
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Syntax highlighting: // Syntax highlighting:
#[cfg(feature = "syntect")]
fn syntax_highlighting(response: &Response) -> Option<ColoredText> { fn syntax_highlighting(response: &Response) -> Option<ColoredText> {
let text = response.text.as_ref()?; let text = response.text.as_ref()?;
let extension_and_rest: Vec<&str> = response.url.rsplitn(2, '.').collect(); let extension_and_rest: Vec<&str> = response.url.rsplitn(2, '.').collect();
@ -204,8 +205,10 @@ fn syntax_highlighting(response: &Response) -> Option<ColoredText> {
} }
/// Lines of text fragments /// Lines of text fragments
#[cfg(feature = "syntect")]
struct ColoredText(Vec<Vec<(syntect::highlighting::Style, String)>>); struct ColoredText(Vec<Vec<(syntect::highlighting::Style, String)>>);
#[cfg(feature = "syntect")]
impl ColoredText { impl ColoredText {
/// e.g. `text_with_extension("fn foo() {}", "rs")` /// e.g. `text_with_extension("fn foo() {}", "rs")`
pub fn text_with_extension(text: &str, extension: &str) -> Option<ColoredText> { pub fn text_with_extension(text: &str, extension: &str) -> Option<ColoredText> {
@ -247,6 +250,17 @@ impl ColoredText {
} }
} }
#[cfg(not(feature = "syntect"))]
fn syntax_highlighting(_: &Response) -> Option<ColoredText> {
None
}
#[cfg(not(feature = "syntect"))]
struct ColoredText();
#[cfg(not(feature = "syntect"))]
impl ColoredText {
pub fn ui(&self, _ui: &mut egui::Ui) {}
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Texture/image handling is very manual at the moment. // Texture/image handling is very manual at the moment.