mirror of
https://github.com/sharkdp/bat.git
synced 2025-09-02 11:22:30 +01:00
Extract some private submodules from 'bat::assets' (#1850)
This commit is contained in:
27
src/assets/serialized_syntax_set.rs
Normal file
27
src/assets/serialized_syntax_set.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use syntect::parsing::SyntaxSet;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// A SyntaxSet in serialized form, i.e. bincoded and flate2 compressed.
|
||||
/// We keep it in this format since we want to load it lazily.
|
||||
#[derive(Debug)]
|
||||
pub enum SerializedSyntaxSet {
|
||||
/// The data comes from a user-generated cache file.
|
||||
FromFile(PathBuf),
|
||||
|
||||
/// The data to use is embedded into the bat binary.
|
||||
FromBinary(&'static [u8]),
|
||||
}
|
||||
|
||||
impl SerializedSyntaxSet {
|
||||
pub fn deserialize(&self) -> Result<SyntaxSet> {
|
||||
match self {
|
||||
SerializedSyntaxSet::FromBinary(data) => Ok(from_binary(data, COMPRESS_SYNTAXES)),
|
||||
SerializedSyntaxSet::FromFile(ref path) => {
|
||||
asset_from_cache(path, "syntax set", COMPRESS_SYNTAXES)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user