deps-gen

Crates.iodeps-gen
lib.rsdeps-gen
version0.2.0
sourcesrc
created_at2024-02-23 21:59:05.380566
updated_at2024-02-24 09:52:53.748334
descriptionGenerate a file from template and Cargo.lock
homepagehttps://github.com/picrap/deps-gen
repositoryhttps://github.com/picrap/deps-gen.git
max_upload_size
id1151024
size15,970
Pascal Craponne (picrap)

documentation

README

deps-gen

From Cargo.lock to a generated file.

Why?

The goal is to generate a file from a template with dependencies from Cargo.lock.

How?

Build

In Cargo.toml, add the following line:

[build-dependencies]
deps-gen = "*"

then in your build.rs:

use deps_gen;

fn main() {
    gen_deps();
    // // or
    // let mut configuration = deps::Configuration::new()
    // // do some changes to configuration here
    // deps::gen_with_configuration(configuration);
}

The default configuration will take a src/deps.template.rs file and generate a src/deps.rs .

Templating

The library uses handlebars with the default supported syntax. The supported field are

  • dependencies, an array with the following values
    • name
    • version
    • authors
    • id
    • source
    • description
    • dependencies
    • license
    • license_file
    • targets
    • features
    • manifest_path
    • categories
    • keywords
    • readme
    • repository
    • homepage
    • documentation
    • edition

see Rust manifest reference for fields details

Also note that //{} is replaced with   (an empty string) after template processing. This allows to cleanup.

An example

deps.template.rs:

#[allow(dead_code)]

pub struct License {
    pub name: &'static str,
    pub version: &'static str,
}

impl License {
    pub fn all() -> Vec<Self> {
        vec![
            //{}{{#each dependencies}}
            Self {
                name: "{{name}}",
                version: "{{version}}",
            },
            //{}{{/each}}
        ]
    }
}
Commit count: 0

cargo fmt