jrsonnet-importers

Crates.iojrsonnet-importers
lib.rsjrsonnet-importers
version0.2.0
sourcesrc
created_at2024-11-13 16:22:58.821316
updated_at2024-11-13 16:31:25.994542
descriptionMore importers for jrsonnet
homepage
repositoryhttps://github.com/Jezza/jrsonnet-importers
max_upload_size
id1446722
size13,677
(Jezza)

documentation

README

Importers for all!

This just adds some extra importers for use with jrsonnet.

  • jrsonnet_importers::CargoTracer All files imported that resolve to a physical file on the system are emitted via the cargo directives.

  • jrsonnet_importers::from_fn Allows you to easily define semantics of imported files.

#[derive(rust_embed::Embed)]
#[folder = "api/"]
#[prefix = "api/"]
struct ApiFiles;

use jrsonnet_importers::*;

let importer = CargoTracer::new({
    // So we can import files next to the 'input' file.
    let folders = vec![parent.to_path_buf()];
    
    from_fn(move |from, path| {
        // Handy function to resolve a file from folders.
        if let Some(source) = resolve_from(&folders, path)? {
            return Ok(Some(source));
        }
        
        // Failing that, we attempt to resolve the file via the embedded files, courtesy of `rust_embed`
        if let Some(source) = resolve_embed::<ApiFiles>(from, path)? {
            return Ok(Some(source));
        }
        
        Ok(None)
    })
});

state.set_import_resolver(importer);

Commit count: 3

cargo fmt