Struct cargo_toml_builder::CargoToml
source · pub struct CargoToml {
pub name: Option<String>,
pub authors: Option<Vec<String>>,
/* private fields */
}
Expand description
Main builder struct
This is the builder that all other methods are called on. You can use ::builder()
,
::new()
, or ::default()
to get an initialized instance
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::builder()
.name("my-project")
.author("Me <me@me.com>")
.build()?;
assert_eq!(cargo_toml.to_string(), r#"
[package]
name = "my-project"
version = "0.1.0"
authors = ["Me <me@me.com>"]
[dependencies]
"#);
Fields
name: Option<String>
The name that will be used for this Cargo.toml
The list of authors that will be used for this Cargo.toml
Implementations
sourceimpl CargoToml
impl CargoToml
sourcepub fn new() -> CargoToml
pub fn new() -> CargoToml
Construct a new instance
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::CargoToml;
let cargo_toml = CargoToml::new();
sourcepub fn builder() -> CargoToml
pub fn builder() -> CargoToml
Construct a new instance
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::CargoToml;
let cargo_toml = CargoToml::builder();
sourcepub fn name(&mut self, name: &str) -> &mut Self
pub fn name(&mut self, name: &str) -> &mut Self
Sets the package.name
of the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::CargoToml;
let cargo_toml = CargoToml::new()
.name("my-rust-project")
.build()?;
/*
[package]
name = "my-rust-project"
*/
Add an author to the package.authors
property
Note: This will append an entry to the underlying Vec, it will not affect any other
author
s that have been set
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.author("Me <me@me.com>")
.build()?;
/*
[package]
authors = ["Me <me@me.com>"]
*/
Set the list of authors for the package.authors
property
Note: This will replace any existing list of authors
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.authors(&[
"Me <me@me.com>".into(),
"You <you@you.com>".into()
])
.build()?;
/*
[package]
authors = ["Me <me@me.com>", "You <you@you.com>"]
*/
sourcepub fn version(&mut self, version: &str) -> &mut Self
pub fn version(&mut self, version: &str) -> &mut Self
Sets the package.version
of the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.version("1.1.0")
.build()?;
/*
[package]
version = "1.1.0"
*/
sourcepub fn build_script(&mut self, build: &str) -> &mut Self
pub fn build_script(&mut self, build: &str) -> &mut Self
Sets the package.build
property of the project
TODO: currently impossible to generate build = false
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.build_script("./my-build-script.rs")
.build()?;
/*
[package]
build = "./my-build-script"
*/
sourcepub fn documentation(&mut self, documentation: &str) -> &mut Self
pub fn documentation(&mut self, documentation: &str) -> &mut Self
Sets the package.documentation
property of the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.documentation("https://docs.rs/my-project")
.build()?;
/*
[package]
documentation = "https://docs.rs/my-project"
*/
sourcepub fn exclude(&mut self, exclude: &str) -> &mut Self
pub fn exclude(&mut self, exclude: &str) -> &mut Self
Adds an exclusion pattern to the package.exclude
property
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.exclude("build/**/*.o")
.build()?;
/*
[package]
exclude = ["build/**/*.o"]
*/
sourcepub fn excludes(&mut self, excludes: &[String]) -> &mut Self
pub fn excludes(&mut self, excludes: &[String]) -> &mut Self
Sets the list of exclusion patterns for the package.exclude
property
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.excludes(&[
"build/**/*.o".into(),
"doc/**/*.html".into(),
])
.build()?;
/*
[package]
exclude = ["build/**/*.o", "doc/**/*.html"]
*/
sourcepub fn include(&mut self, include: &str) -> &mut Self
pub fn include(&mut self, include: &str) -> &mut Self
Adds an inclusion pattern to the package.include
property
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.include("src/**/*")
.build()?;
/*
[package]
include = ["src/**/*"]
*/
sourcepub fn includes(&mut self, includes: &[String]) -> &mut Self
pub fn includes(&mut self, includes: &[String]) -> &mut Self
Sets the inclusion patterns for the package.include
property
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.includes(&[
"src/**/*".into(),
"Cargo.toml".into(),
])
.build()?;
/*
[package]
include = ["src/**/*.html, "Cargo.toml"]
*/
sourcepub fn publish(&mut self, publish: bool) -> &mut Self
pub fn publish(&mut self, publish: bool) -> &mut Self
Sets the package.publish
property
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.publish(false)
.build()?;
/*
[package]
publish = false
*/
sourcepub fn workspace_root(&mut self, workspace_root: &str) -> &mut Self
pub fn workspace_root(&mut self, workspace_root: &str) -> &mut Self
Sets the package.workspace
property
(this is the workspace = "/path/to/workspace"
property, not be be confused with the
[workspace]
table that can also be added to the document)
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.workspace_root("/path/to/workspace/root")
.build()?;
/*
[package]
workspace = "/path/to/workspace/root"
*/
sourcepub fn description(&mut self, description: &str) -> &mut Self
pub fn description(&mut self, description: &str) -> &mut Self
Sets the package.description
property
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.description("This is my new Rust project")
.build()?;
/*
[package]
description = "This is my new Rust project"
*/
sourcepub fn homepage(&mut self, homepage: &str) -> &mut Self
pub fn homepage(&mut self, homepage: &str) -> &mut Self
Sets the package.homepage
property
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.homepage("https://my.domain/")
.build()?;
/*
[package]
homepage = "https://my.domain/"
*/
sourcepub fn repository(&mut self, repository: &str) -> &mut Self
pub fn repository(&mut self, repository: &str) -> &mut Self
Sets the package.repository
property
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.repository("https://gitlab.com/me/my-project")
.build()?;
/*
[package]
repository = "https://gitlab.com/me/my-project"
*/
sourcepub fn readme(&mut self, readme: &str) -> &mut Self
pub fn readme(&mut self, readme: &str) -> &mut Self
Sets the package.readme
property
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.readme("README.adoc")
.build()?;
/*
[package]
readme = "README.adoc"
*/
sourcepub fn keyword(&mut self, keyword: &str) -> &mut Self
pub fn keyword(&mut self, keyword: &str) -> &mut Self
Adds a keyword to the package.keywords
property
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.keyword("async")
.build()?;
/*
[package]
keywords = ["async"]
*/
sourcepub fn keywords(&mut self, keywords: &[String]) -> &mut Self
pub fn keywords(&mut self, keywords: &[String]) -> &mut Self
Sets the list of keywords for the package.keywords
property
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.keywords(&[
"async".into(),
"networking".into(),
])
.build()?;
/*
[package]
keywords = ["async", "networking"]
*/
sourcepub fn category(&mut self, category: &str) -> &mut Self
pub fn category(&mut self, category: &str) -> &mut Self
Adds a category to the package.categories
property
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.category("filesystem")
.build()?;
/*
[package]
categories = ["filesystem"]
*/
sourcepub fn categories(&mut self, categories: &[String]) -> &mut Self
pub fn categories(&mut self, categories: &[String]) -> &mut Self
Sets the list of categories for the package.categories
property
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.categories(&[
"filesystem".into(),
"testing".into(),
])
.build()?;
/*
[package]
categories = ["filesystem", "testing"]
*/
sourcepub fn license<L: Into<License>>(&mut self, license: L) -> &mut Self
pub fn license<L: Into<License>>(&mut self, license: L) -> &mut Self
Adds a license to the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.license(License::Mit)
.build()?;
/*
[package]
license = "MIT"
*/
sourcepub fn licenses<L: Into<License> + Clone>(&mut self, licenses: &[L]) -> &mut Self
pub fn licenses<L: Into<License> + Clone>(&mut self, licenses: &[L]) -> &mut Self
Sets a list of licenses for the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.licenses(&[
License::Mit,
License::Apache2,
])
.build()?;
/*
[package]
license = "MIT/Apache-2.0"
*/
sourcepub fn license_file(&mut self, license_file: &str) -> &mut Self
pub fn license_file(&mut self, license_file: &str) -> &mut Self
Sets the location for the license file of the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.license_file("LICENSE")
.build()?;
/*
[package]
license-file = "LICENSE"
*/
sourcepub fn appveyor<A: Into<Appveyor>>(&mut self, appveyor: A) -> &mut Self
pub fn appveyor<A: Into<Appveyor>>(&mut self, appveyor: A) -> &mut Self
Sets the badges.appveyor
table for the project
You can import the “Appveyor” struct from cargo_toml_builder::types
, but this method will
take anything that implements Into<Appveyor>
, which String
and &str
do. So if all you
want is to add the repo, you can just pass some kind of string to this method and it should
Just Work.
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::Appveyor;
let appveyor_badge = Appveyor::new("https://gitlab.com/me/my-project");
let cargo_toml = CargoToml::new()
.appveyor(appveyor_badge)
// or this will also work, and result in the same output:
// .appveyor("https://gitlab.com/me/my-project")
.build()?;
/*
[badges]
appveyor = { repository = "https://gitlab.com/me/my-project" }
*/
sourcepub fn circle_ci<C: Into<CircleCi>>(&mut self, circle_ci: C) -> &mut Self
pub fn circle_ci<C: Into<CircleCi>>(&mut self, circle_ci: C) -> &mut Self
Sets the badges.circle-ci
table for the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::CircleCi;
let circe_ci_badge = CircleCi::new("https://gitlab.com/me/my-project");
let cargo_toml = CargoToml::new()
.circle_ci(circe_ci_badge)
.build()?;
/*
[badges]
circle-ci = { repository = "https://gitlab.com/me/my-project" }
*/
sourcepub fn gitlab<G: Into<Gitlab>>(&mut self, gitlab: G) -> &mut Self
pub fn gitlab<G: Into<Gitlab>>(&mut self, gitlab: G) -> &mut Self
Sets the badges.gitlab
table for the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::Gitlab;
let gitlab_badge = Gitlab::new("https://gitlab.com/me/my-project");
let cargo_toml = CargoToml::new()
.gitlab(gitlab_badge)
.build()?;
/*
[badges]
gitlab = { repository = "https://gitlab.com/me/my-project" }
*/
sourcepub fn travis_ci<T: Into<TravisCi>>(&mut self, travis_ci: T) -> &mut Self
pub fn travis_ci<T: Into<TravisCi>>(&mut self, travis_ci: T) -> &mut Self
Sets the badges.travis-ci
table for the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::TravisCi;
let travis_ci_badge = TravisCi::new("https://gitlab.com/me/my-project");
let cargo_toml = CargoToml::new()
.travis_ci(travis_ci_badge)
.build()?;
/*
[badges]
travis-ci = { repository = "https://gitlab.com/me/my-project" }
*/
sourcepub fn codecov<C: Into<Codecov>>(&mut self, codecov: C) -> &mut Self
pub fn codecov<C: Into<Codecov>>(&mut self, codecov: C) -> &mut Self
Sets the badges.codecov
table for the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::Codecov;
let codecov_badge = Codecov::new("https://gitlab.com/me/my-project");
let cargo_toml = CargoToml::new()
.codecov(codecov_badge)
.build()?;
/*
[badges]
codecov = { repository = "https://gitlab.com/me/my-project" }
*/
sourcepub fn coveralls<C: Into<Coveralls>>(&mut self, coveralls: C) -> &mut Self
pub fn coveralls<C: Into<Coveralls>>(&mut self, coveralls: C) -> &mut Self
Sets the badges.coveralls
table for the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::Coveralls;
let coveralls_badge = Coveralls::new("https://gitlab.com/me/my-project");
let cargo_toml = CargoToml::new()
.coveralls(coveralls_badge)
.build()?;
/*
[badges]
coveralls = { repository = "https://gitlab.com/me/my-project" }
*/
sourcepub fn is_it_maintained_time(&mut self, time: &str) -> &mut Self
pub fn is_it_maintained_time(&mut self, time: &str) -> &mut Self
Sets the badges.is-it-maintained-issue-resolution
table for the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::Coveralls;
let cargo_toml = CargoToml::new()
.is_it_maintained_time("https://gitlab.com/me/my-project")
.build()?;
/*
[badges]
is-it-maintained-issue-resolution = { repository = "https://gitlab.com/me/my-project" }
*/
sourcepub fn is_it_maintained_issues(&mut self, issues: &str) -> &mut Self
pub fn is_it_maintained_issues(&mut self, issues: &str) -> &mut Self
Sets the badges.is-it-maintained-open-issues
table for the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::Coveralls;
let cargo_toml = CargoToml::new()
.is_it_maintained_issues("https://gitlab.com/me/my-project")
.build()?;
/*
[badges]
is-it-maintained-open-issues = { repository = "https://gitlab.com/me/my-project" }
*/
sourcepub fn maintenance<M: Into<MaintenanceStatus>>(
&mut self,
maintenance: M
) -> &mut Self
pub fn maintenance<M: Into<MaintenanceStatus>>(
&mut self,
maintenance: M
) -> &mut Self
Sets the badges.maintenance
table for the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::MaintenanceStatus;
let cargo_toml = CargoToml::new()
.maintenance(MaintenanceStatus::AsIs)
.build()?;
/*
[badges]
maintenance = { status = "as-is" }
*/
sourcepub fn dependency<D: Into<Dependency>>(&mut self, dependency: D) -> &mut Self
pub fn dependency<D: Into<Dependency>>(&mut self, dependency: D) -> &mut Self
Adds a dependency to the dependencies
table
The Dependency
struct is imported through the prelude, but you can also pass anything to
this that implements Into<Dependency>
which String
and &str
do. If you pass a string
to this method, it will add a regular crate dependency, with version "*"
. You can use the
extension methods from DependencyExt
to use a string to
construct a Dependency
object.
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.dependency("env_logger".version("0.5.6"))
.build()?;
/*
[dependencies]
env_logger = "0.5.6"
*/
sourcepub fn dependencies<D: Into<Dependency> + Clone>(
&mut self,
dependencies: &[D]
) -> &mut Self
pub fn dependencies<D: Into<Dependency> + Clone>(
&mut self,
dependencies: &[D]
) -> &mut Self
Set the dependencies
table for the project
Note: This will replace any dependencies current attached to the object
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.dependencies(&[
"env_logger".version("0.5.6"),
"tokio".version("0.2"),
])
.build()?;
/*
[dependencies]
env_logger = "0.5.6"
tokio = "0.2"
*/
sourcepub fn dev_dependency<D: Into<Dependency>>(&mut self, dependency: D) -> &mut Self
pub fn dev_dependency<D: Into<Dependency>>(&mut self, dependency: D) -> &mut Self
Add a dev-dependencies
entry to the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.dev_dependency("hamcrest".version("0.1.5"))
.build()?;
/*
[dev-dependencies]
hamcrest = "0.1.5"
*/
sourcepub fn dev_dependencies<D: Into<Dependency> + Clone>(
&mut self,
dependencies: &[D]
) -> &mut Self
pub fn dev_dependencies<D: Into<Dependency> + Clone>(
&mut self,
dependencies: &[D]
) -> &mut Self
Set the list of dev-dependencies
for the project
Note: This will replace any dev-dependencies currently attached to the object
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.dev_dependencies(&[
"hamcrest".version("0.1.5"),
"my-test-lib".path("../my-test-lib")
])
.build()?;
/*
[dev-dependencies]
hamcrest = "0.1.5"
my-test-lib = { path = "../my-test-lib" }
*/
sourcepub fn build_dependency<D: Into<Dependency>>(
&mut self,
dependency: D
) -> &mut Self
pub fn build_dependency<D: Into<Dependency>>(
&mut self,
dependency: D
) -> &mut Self
Add an entry to the build-dependencies
table for the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.build_dependency("gcc".version("0.3.54"))
.build()?;
/*
[build-dependencies]
gcc = "0.3.54"
*/
sourcepub fn build_dependencies<D: Into<Dependency> + Clone>(
&mut self,
dependencies: &[D]
) -> &mut Self
pub fn build_dependencies<D: Into<Dependency> + Clone>(
&mut self,
dependencies: &[D]
) -> &mut Self
Set the list of build-dependencies
for the project
Note: this will replace any build dependencies currently attached to the object
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.build_dependencies(&[
"gcc".version("0.3.54"),
"cmake".version("0.1.29"),
])
.build()?;
/*
[build-dependencies]
gcc = "0.3.54"
cmake = "0.1.29"
*/
sourcepub fn target_dependency<D: Into<Dependency>>(
&mut self,
name: &str,
dependency: D
) -> &mut Self
pub fn target_dependency<D: Into<Dependency>>(
&mut self,
name: &str,
dependency: D
) -> &mut Self
Add a dependency to a target
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.target_dependency("cfg(unix)", "openssl".version("1.0.1"))
.build()?;
/*
[target."cfg(unix)".dependencies]
openssl = "1.0.1"
*/
sourcepub fn target_dependencies<D: Into<Dependency> + Clone>(
&mut self,
name: &str,
dependencies: &[D]
) -> &mut Self
pub fn target_dependencies<D: Into<Dependency> + Clone>(
&mut self,
name: &str,
dependencies: &[D]
) -> &mut Self
Set the dependency list for a target
Note: This will replace any dependencies current attached to the target
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.target_dependencies("cfg(unix)", &[
"openssl".version("1.0.1"),
"libc".version("0.2.40"),
])
.build()?;
/*
[target."cfg(unix)".dependencies]
openssl = "1.0.1"
libc = "0.2.40"
*/
sourcepub fn profile_dev(&mut self, profile_dev: Profile) -> &mut Self
pub fn profile_dev(&mut self, profile_dev: Profile) -> &mut Self
Set the properties of the dev profile
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::{Profile, PanicStrategy};
let profile = Profile::new().panic(PanicStrategy::Abort).build();
let cargo_toml = CargoToml::new()
.profile_dev(profile)
.build()?;
/*
[profile.dev]
panic = "abort"
*/
sourcepub fn profile_release(&mut self, profile_dev: Profile) -> &mut Self
pub fn profile_release(&mut self, profile_dev: Profile) -> &mut Self
Set the properties of the release profile
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::{Profile, PanicStrategy};
let profile = Profile::new().panic(PanicStrategy::Abort).build();
let cargo_toml = CargoToml::new()
.profile_release(profile)
.build()?;
/*
[profile.release]
panic = "abort"
*/
sourcepub fn profile_test(&mut self, profile_dev: Profile) -> &mut Self
pub fn profile_test(&mut self, profile_dev: Profile) -> &mut Self
Set the properties of the test profile
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::{Profile, PanicStrategy};
let profile = Profile::new().panic(PanicStrategy::Abort).build();
let cargo_toml = CargoToml::new()
.profile_test(profile)
.build()?;
/*
[profile.test]
panic = "abort"
*/
sourcepub fn profile_bench(&mut self, profile_dev: Profile) -> &mut Self
pub fn profile_bench(&mut self, profile_dev: Profile) -> &mut Self
Set the properties of the bench profile
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::{Profile, PanicStrategy};
let profile = Profile::new().panic(PanicStrategy::Abort).build();
let cargo_toml = CargoToml::new()
.profile_bench(profile)
.build()?;
/*
[profile.bench]
panic = "abort"
*/
sourcepub fn profile_doc(&mut self, profile_dev: Profile) -> &mut Self
pub fn profile_doc(&mut self, profile_dev: Profile) -> &mut Self
Set the properties of the doc profile
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::{Profile, PanicStrategy};
let profile = Profile::new().panic(PanicStrategy::Abort).build();
let cargo_toml = CargoToml::new()
.profile_doc(profile)
.build()?;
/*
[profile.doc]
panic = "abort"
*/
sourcepub fn feature<F: Into<Feature>>(&mut self, feature: F) -> &mut Self
pub fn feature<F: Into<Feature>>(&mut self, feature: F) -> &mut Self
Add a feature to the project
The user can attach dependencies, and the labels for other features, to a Feature
object.
If a Dependency is added, it will automatically be added to the [dependencies]
section of
the document with the optional = true
option added. If you need different behavior, add
the name of the dependency using the .feature
builder method and add the dependency to
the correct section manually.
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let nightly = Feature::new("nightly").dependency("clippy".version("0.0.191")).build();
let cargo_toml = CargoToml::new()
.feature(nightly)
.build()?;
/*
[features]
nightly = ['clippy']
[dependencies]
clippy = { version = "0.0.191", optional = true }
*/
Or, to add a feature dependency to, say, [dev-dependencies]
:
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let nightly = Feature::new("nightly").feature("clippy").build();
let cargo_toml = CargoToml::new()
.feature(nightly)
.dev_dependency("clippy".version("0.0.191").optional(true))
.build()?;
/*
[features]
nightly = ['clippy']
[dev-dependencies]
clippy = { version = "0.0.191", optional = true }
*/
sourcepub fn workspace(&mut self, workspace: Workspace) -> &mut Self
pub fn workspace(&mut self, workspace: Workspace) -> &mut Self
Set the workspace config table for the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::Workspace;
let workspace = Workspace::new().member("/path/to/member1").build();
let cargo_toml = CargoToml::new()
.workspace(workspace)
.build()?;
/*
[workspace]
members = ["/path/to/member1"]
*/
sourcepub fn lib<T: Into<LibTarget>>(&mut self, target: T) -> &mut Self
pub fn lib<T: Into<LibTarget>>(&mut self, target: T) -> &mut Self
Set a [lib]
target for the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let target = LibTarget::new().name("my-lib").path("src/my-lib.rs").build();
let cargo_toml = CargoToml::new()
.lib(target)
.build()?;
/*
[lib]
name = "my-lib"
path = "src/my-lib.rs"
*/
sourcepub fn bin<T: Into<BinTarget>>(&mut self, target: T) -> &mut Self
pub fn bin<T: Into<BinTarget>>(&mut self, target: T) -> &mut Self
Add a [[bin]]
target for the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let target = BinTarget::new().name("my-bin").path("src/bin/my-bin.rs").build();
let cargo_toml = CargoToml::new()
.bin(target)
.build()?;
/*
[dependencies]
<name> = <value>
*/
sourcepub fn bins(&mut self, target: &[BinTarget]) -> &mut Self
pub fn bins(&mut self, target: &[BinTarget]) -> &mut Self
Set the [[bin]]
targets for the project
Note: This will replace any bin targets currently attached to the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.bins(&[
BinTarget::new().name("my-bin-1").path("src/bin/my-bin-1.rs").build(),
BinTarget::new().name("my-bin-2").path("src/bin/my-bin-2.rs").build(),
])
.build()?;
/*
[dependencies]
<name> = <value>
*/
sourcepub fn bench<T: Into<BenchTarget>>(&mut self, target: T) -> &mut Self
pub fn bench<T: Into<BenchTarget>>(&mut self, target: T) -> &mut Self
Add a [bench]
target for the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let target = BenchTarget::new().name("my-benchmark").path("bench/my-benchmark.rs").build();
let cargo_toml = CargoToml::new()
.bench(target)
.build()?;
/*
[dependencies]
<name> = <value>
*/
sourcepub fn benches(&mut self, target: &[BenchTarget]) -> &mut Self
pub fn benches(&mut self, target: &[BenchTarget]) -> &mut Self
Set the list of [[bench]]
targets for the project
Note: This will replace any bench targets currently attached to the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.benches(&[
BenchTarget::new().name("my-benchmark-1").path("bench/my-benchmark-1.rs").build(),
BenchTarget::new().name("my-benchmark-2").path("bench/my-benchmark-2.rs").build(),
])
.build()?;
/*
[[bench]]
name = "my-benchmark-1"
path = "bench/my-benchmark-1.rs"
[[bench]]
name = "my-benchmark-2"
path = "bench/my-benchmark-2.rs"
*/
sourcepub fn test<T: Into<TestTarget>>(&mut self, target: T) -> &mut Self
pub fn test<T: Into<TestTarget>>(&mut self, target: T) -> &mut Self
Add a [[test]]
target to the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let target = TestTarget::new().name("my-test").path("tests/my-test.rs").build();
let cargo_toml = CargoToml::new()
.test(target)
.build()?;
/*
[[test]]
name = "my-test"
path = "tests/my-test.rs"
*/
sourcepub fn tests(&mut self, target: &[TestTarget]) -> &mut Self
pub fn tests(&mut self, target: &[TestTarget]) -> &mut Self
Set the [[test]]
targets for the project
Note: This will replace any test targets currently attached to the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.tests(&[
TestTarget::new().name("my-test-1").path("tests/my-test-1.rs").build(),
TestTarget::new().name("my-test-2").path("tests/my-test-2.rs").build(),
])
.build()?;
/*
[[test]]
name = "my-test-1"
path = "tests/my-test-1.rs"
[[test]]
name = "my-test-2"
path = "tests/my-test-2.rs"
*/
sourcepub fn example<T: Into<ExampleTarget>>(&mut self, target: T) -> &mut Self
pub fn example<T: Into<ExampleTarget>>(&mut self, target: T) -> &mut Self
Add an [[example]]
target to the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let target = ExampleTarget::new().name("my-example").path("examples/my-example.rs").build();
let cargo_toml = CargoToml::new()
.example(target)
.build()?;
/*
[[example]]
name = "my-example"
path = "examples/my-example.rs"
*/
sourcepub fn examples(&mut self, target: &[ExampleTarget]) -> &mut Self
pub fn examples(&mut self, target: &[ExampleTarget]) -> &mut Self
Set the list of [[example]]
targets for the project
Note: This will replace any [[example]]
targets currently attached to the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.examples(&[
ExampleTarget::new().name("my-example-1").path("examples/my-example-1.rs").build(),
ExampleTarget::new().name("my-example-2").path("examples/my-example-2.rs").build(),
])
.build()?;
/*
[[example]]
name = "my-example-1"
path = "examples/my-example-1.rs"
[[example]]
name = "my-example-2"
path = "examples/my-example-2.rs"
*/
sourcepub fn patch(&mut self, patch: PatchSet) -> &mut Self
pub fn patch(&mut self, patch: PatchSet) -> &mut Self
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::PatchSet;
let patchset = PatchSet::new("crates-io")
.patch("env_logger".repo("https://gitlab.com/me/env_logger.git"))
.build();
let cargo_toml = CargoToml::new()
.patch(patchset)
.build()?;
/*
[patch.crates-io]
env_logger = { git = "https://gitlab.com/me/env_logger.git" }
*/
sourcepub fn patches(&mut self, patches: &[PatchSet]) -> &mut Self
pub fn patches(&mut self, patches: &[PatchSet]) -> &mut Self
Set the list of patch sets for the project
Note: This will replace any patch sets currently attached to the object
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
use cargo_toml_builder::types::PatchSet;
let cargo_toml = CargoToml::new()
.patches(&[
PatchSet::new("crates-io")
.patch("env_logger".repo("https://gitlab.com/me/env_logger.git"))
.build(),
PatchSet::new("https://github.com/example/baz")
.patch("baz".repo("https://github.com/example/patched-baz"))
.build(),
])
.build()?;
/*
[patch.crates-io]
env_logger = { git = "https://gitlab.com/me/env_logger.git" }
[patch."https://github.com/example/baz"]
baz = { git = "https://github.com/example/patched-baz" }
*/
sourcepub fn replace<D: Into<Dependency>>(&mut self, dependency: D) -> &mut Self
pub fn replace<D: Into<Dependency>>(&mut self, dependency: D) -> &mut Self
Add a [replace]
entry to the project
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.replace("foo:0.1.0".repo("https://github.com/example/foo"))
.build()?;
/*
[replace]
"foo:0.1.0" = { git = "https://github.com/example/foo" }
*/
sourcepub fn build(&self) -> Result<Document, Error>
pub fn build(&self) -> Result<Document, Error>
Build a toml_edit::Document
object from this builder
Example
extern crate cargo_toml_builder;
use cargo_toml_builder::prelude::*;
let cargo_toml = CargoToml::new()
.name("my-project")
.author("Me <me@me.com>")
.build()?;
/*
[package]
name = "my-project"
version = "0.1.0"
authors = ["Me <me@me.com>"]
[dependencies]
*/