pub struct TmplBuilder {
    pub pkg_name: String,
    pub pkg_type: Option<PkgType>,
    pub pkg_info: Option<PkgInfo>,
    pub deps: Option<Vec<String>>,
}

Fields§

§pkg_name: String§pkg_type: Option<PkgType>§pkg_info: Option<PkgInfo>§deps: Option<Vec<String>>

Implementations§

Initializes a new TmplBuilder with nothing but pkg_name set.

Initializes a new TmplBuilder from a PkgInfo. Useful for testing or as a shortcut

Gets the PkgType of the package of the TmplBuilder that’s passed into the function

Sets the PkgType of the package of the TmplBuilder that’s passed into the function

Gets the PkgInfo of the package of the TmplBuilder that’s passed into the function

Sets the PkgInfo of the package of the TmplBuilder that’s passed into the function

Gets the dependencies of the TmplBuilder that’s passed into the function

Checks if a Gem or PerlDist is built into Ruby/Perl.

Updates a Template

Example
use libtmplgen::{PkgInfo, Template, TmplBuilder};
use std::fs::File;
use std::io::prelude::*;

// Do note that we only manually create a PkgInfo here to make the example easier to understand
let pkg_info_crate = PkgInfo {
       pkg_name: "tmplgen".to_string(),
       version: "0.6.0".to_string(),
       description: "Void Linux template generator for language-specific package managers"
           .to_string(),
       homepage: "https://github.com/Cogitri/tmplgen".to_string(),
       license: vec!["GPL-3.0-or-later".to_string()],
       dependencies: None,
       sha: "afc403bf69ad4da168938961b0f02da86ef29d655967cfcbacc8201e1327aff4".to_string(),
       download_url: Some(
           "https://static.crates.io/crates/tmplgen/tmplgen-${version}.crate".to_string(),
       ),
};

let mut old_template = Template { inner: String::new() };
// Open whatever file you want to below.
let mut file = File::open("src/lib/tests/template_test_crate.in").unwrap();
file.read_to_string(&mut old_template.inner).unwrap();

// This will return a [Template](crate::types::Template), which is updated to 0.6.0 (as specified by pkg_info_crate above)
// Use TmplBuilder::new("tmplgen").get_info() to manually get the info we manually set in pkg_info_crate!
// Won't update `homepage`, `distfiles` and `short_desc`, set the second argument to `true` for that
let template_updated = TmplBuilder::from_pkg_info(pkg_info_crate).get_type().unwrap().update(&old_template, false).unwrap();

// Write the [Template](crate::types::Template) to `./template`
let mut file = File::create("./template").unwrap();
file.write_all(template_updated.inner.as_bytes()).unwrap();

Generates a new Template

Example
use libtmplgen::{PkgInfo, PkgType, TmplBuilder};
use std::fs::File;
use std::io::prelude::*;

// Do note that we only manually create a PkgInfo here to make the example easier to understand
let pkg_info_crate = PkgInfo {
       pkg_name: "tmplgen".to_string(),
       version: "0.6.0".to_string(),
       description: "Void Linux template generator for language-specific package managers"
           .to_string(),
       homepage: "https://github.com/Cogitri/tmplgen".to_string(),
       license: vec!["GPL-3.0-or-later".to_string()],
       dependencies: None,
       sha: "afc403bf69ad4da168938961b0f02da86ef29d655967cfcbacc8201e1327aff4".to_string(),
       download_url: Some(
           "https://static.crates.io/crates/tmplgen/tmplgen-${version}.crate".to_string(),
       ),
};

// Use TmplBuilder::new("tmplgen").get_type.generate() to do this automatically instead of
// setting PkgInfo and PkgType manually
let template = TmplBuilder::from_pkg_info(pkg_info_crate).set_type(PkgType::Crate).generate().unwrap();

// Write the [Template](crate::types::Template) to `./template`
let mut file = File::create("./template").unwrap();
file.write_all(template.inner.as_bytes()).unwrap();
Errors
  • Errors out if any of the underlying functions fails

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.