#toml #cargo #builder #clippy #smith

cargo-toml-builder

A builder for generating Cargo.toml files

3 releases (breaking)

Uses old Rust 2015

0.3.0 May 2, 2019
0.2.0 Nov 26, 2018
0.1.0 Apr 2, 2018

#248 in Build Utils

Download history 10/week @ 2022-08-13 5/week @ 2022-08-20 8/week @ 2022-08-27 9/week @ 2022-09-03 17/week @ 2022-09-10 7/week @ 2022-09-17 5/week @ 2022-09-24 14/week @ 2022-10-01 10/week @ 2022-10-08 5/week @ 2022-10-15 6/week @ 2022-10-22 15/week @ 2022-10-29 17/week @ 2022-11-05 10/week @ 2022-11-12 12/week @ 2022-11-19 6/week @ 2022-11-26

51 downloads per month

AGPL-3.0

155KB
2K SLoC

Cargo.toml Builder

Programmatically generate Cargo.toml files

Installation

Add the following to your Cargo.toml file:

[dependencies]
cargo-toml-builder = "0.3"

and the following to your crate root:

extern crate cargo_toml_builder;

Example

extern crate cargo_toml_builder;

use cargo_toml_builder::prelude::*;

let cargo_toml = CargoToml::builder()
                      .name("my-project")
                      .version("1.0.0")
                      .author("Alice Smith <asmith@example.com>")
                      .dependency("env_logger".version("0.5.6"))
                      .feature(Feature::new("nightly").dependency("clippy"))
                      .build()?;

assert_eq!(cargo_toml.to_string(), r#"
[package]
name = "my-project"
version = "1.0.0"
authors = ["Alice Smith <asmith@example.com>"]

[dependencies]
env_logger = "0.5.6"
clippy = {"version" = "*", optional = true}

[features]
nightly = ["clippy"]
"#);

lib.rs:

Cargo.toml Builder

Programmatically create Cargo.toml files

Example

extern crate cargo_toml_builder;

use cargo_toml_builder::prelude::*;
# use std::error::Error;
# fn main() -> Result<(), Box<dyn Error>> {
let cargo_toml = CargoToml::builder()
                    .name("my-project")
                    .version("1.0.0")
                    .author("Alice Smith <asmith@example.com>")
                    .dependency("env_logger".version("0.5.6"))
                    .build()?;
assert_eq!(cargo_toml.to_string(), r#"
[package]
name = "my-project"
version = "1.0.0"
authors = ["Alice Smith <asmith@example.com>"]

[dependencies]
env_logger = "0.5.6"
"#);
#   Ok(())
# }

Dependencies

~2.5MB
~46K SLoC