Skip to main content

Preprocessor

Trait Preprocessor 

Source
pub trait Preprocessor: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn transform_type(&self) -> TransformType;
    fn matches_extension(&self, filename: &str) -> bool;
    fn stripped_name(&self, filename: &str) -> String;
    fn expand(&self, source: &Path, fs: &dyn Fs) -> Result<Vec<ExpandedFile>>;
}
Expand description

The core preprocessor abstraction.

Each preprocessor is a small struct that implements this trait. Preprocessors are stored in a PreprocessorRegistry and dispatched by file extension at preprocessing time.

Preprocessors are pure transformers — they read source files and produce expanded content. Writing to the datastore is handled by the pipeline, not by individual preprocessors.

Required Methods§

Source

fn name(&self) -> &str

Unique name for this preprocessor (e.g. "template", "plist").

Source

fn transform_type(&self) -> TransformType

The safety model for this transformation.

Source

fn matches_extension(&self, filename: &str) -> bool

Whether this preprocessor handles a file with the given name.

Source

fn stripped_name(&self, filename: &str) -> String

Strip the preprocessor extension to get the logical filename. e.g. "config.toml.tmpl""config.toml".

Source

fn expand(&self, source: &Path, fs: &dyn Fs) -> Result<Vec<ExpandedFile>>

Expand the source file into one or more output files.

For single-file preprocessors (templates): returns one entry. For multi-file preprocessors (archives): returns many entries.

The source path points to the original file in the pack directory.

§Memory

Expanded content is held fully in memory via Vec<u8>. This is appropriate for dotfile-sized payloads (configs, small scripts, small archives). Preprocessors that may handle very large inputs (e.g. multi-hundred-MB archives of pre-built toolchains) should consider adding a streaming path rather than materialising the entire decoded stream at once.

Implementors§