on 448bfaf help sign in
bat/src/assets/serialized_syntax_set.rs
27 lines 787 B history raw
1use std::path::PathBuf;
3use syntect::parsing::SyntaxSet;
5use super::*;
7/// A SyntaxSet in serialized form, i.e. bincoded and flate2 compressed.
8/// We keep it in this format since we want to load it lazily.
9#[derive(Debug)]
10pub enum SerializedSyntaxSet {
11 /// The data comes from a user-generated cache file.
12 FromFile(PathBuf),
14 /// The data to use is embedded into the bat binary.
15 FromBinary(&'static [u8]),
18impl SerializedSyntaxSet {
19 pub fn deserialize(&self) -> Result<SyntaxSet> {
20 match self {
21 SerializedSyntaxSet::FromBinary(data) => Ok(from_binary(data, COMPRESS_SYNTAXES)),
22 SerializedSyntaxSet::FromFile(ref path) => {
23 asset_from_cache(path, "syntax set", COMPRESS_SYNTAXES)
24 }
25 }
26 }