| Crates.io | deps-gen |
| lib.rs | deps-gen |
| version | 0.2.1 |
| created_at | 2024-02-23 21:59:05.380566+00 |
| updated_at | 2025-06-23 16:27:59.746635+00 |
| description | Generate a file from template and Cargo.lock |
| homepage | https://github.com/picrap/deps-gen |
| repository | https://github.com/picrap/deps-gen.git |
| max_upload_size | |
| id | 1151024 |
| size | 38,121 |
From Cargo.lock to a generated file.
The goal is to generate a file from a template with dependencies from Cargo.lock.
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_deps_with_conf(configuration);
}
The default configuration will take a src/deps.template.rs file and generate a src/deps.rs .
The library uses handlebars with the default supported syntax. The supported field are
dependencies, an array with the following values
nameversionauthorsidsourcedescriptiondependencieslicenselicense_filetargetsfeaturesmanifest_pathcategorieskeywordsreadmerepositoryhomepagedocumentationeditionsee Rust manifest reference for fields details
Also note that //{} is replaced with (an empty string) after template processing. This allows to cleanup.
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}}
]
}
}