pub struct Package {
Show 14 fields name: String, vers: String, deps: Vec<Dependency>, files: Vec<PackageFile>, yanked: bool, features: BTreeMap<String, Vec<String>>, local: bool, alternative: bool, invalid_json: bool, proc_macro: bool, links: Option<String>, rust_version: Option<String>, cargo_features: Vec<String>, v: Option<u32>,
}
Expand description

A builder for creating a new package in a registry.

This uses “source replacement” using an automatically generated .cargo/config file to ensure that dependencies will use these packages instead of contacting crates.io. See source-replacement.md for more details on how source replacement works.

Call publish to finalize and create the package.

If no files are specified, an empty lib.rs file is automatically created.

The Cargo.toml file is automatically generated based on the methods called on Package (for example, calling dep() will add to the [dependencies] automatically). You may also specify a Cargo.toml file to override the generated one.

This supports different registry types:

  • Regular source replacement that replaces crates.io (the default).
  • A “local registry” which is a subset for vendoring (see Package::local).
  • An “alternative registry” which requires specifying the registry name (see Package::alternative).

This does not support “directory sources”. See directory.rs for VendorPackage which implements directory sources.

Example

// Publish package "a" depending on "b".
Package::new("a", "1.0.0")
    .dep("b", "1.0.0")
    .file("src/lib.rs", r#"
        extern crate b;
        pub fn f() -> i32 { b::f() * 2 }
    "#)
    .publish();

// Publish package "b".
Package::new("b", "1.0.0")
    .file("src/lib.rs", r#"
        pub fn f() -> i32 { 12 }
    "#)
    .publish();

// Create a project that uses package "a".
let p = project()
    .file("Cargo.toml", r#"
        [package]
        name = "foo"
        version = "0.0.1"

        [dependencies]
        a = "1.0"
    "#)
    .file("src/main.rs", r#"
        extern crate a;
        fn main() { println!("{}", a::f()); }
    "#)
    .build();

p.cargo("run").with_stdout("24").run();

Fields§

§name: String§vers: String§deps: Vec<Dependency>§files: Vec<PackageFile>§yanked: bool§features: BTreeMap<String, Vec<String>>§local: bool§alternative: bool§invalid_json: bool§proc_macro: bool§links: Option<String>§rust_version: Option<String>§cargo_features: Vec<String>§v: Option<u32>

Implementations§

Creates a new package builder. Call publish() to finalize and build the package.

Call with true to publish in a “local registry”.

See source-replacement.html#local-registry-sources for more details on local registries. See local_registry.rs for the tests that use this.

Call with true to publish in an “alternative registry”.

The name of the alternative registry is called “alternative”.

See src/doc/src/reference/registries.md for more details on alternative registries. See alt_registry.rs for the tests that use this.

Adds a file to the package.

Adds a file with a specific Unix mode.

Adds a symlink to a path to the package.

Adds an “extra” file that is not rooted within the package.

Normal files are automatically placed within a directory named $PACKAGE-$VERSION. This allows you to override that behavior, typically for testing invalid behavior.

Adds a normal dependency. Example:

[dependencies]
foo = {version = "1.0"}

Adds a dependency with the given feature. Example:

[dependencies]
foo = {version = "1.0", "features": ["feat1", "feat2"]}

Adds a platform-specific dependency. Example:

[target.'cfg(windows)'.dependencies]
foo = {version = "1.0"}

Adds a dependency to the alternative registry.

Adds a dev-dependency. Example:

[dev-dependencies]
foo = {version = "1.0"}

Adds a build-dependency. Example:

[build-dependencies]
foo = {version = "1.0"}

Specifies whether or not the package is “yanked”.

Specifies whether or not this is a proc macro.

Adds an entry in the [features] section.

Specify a minimal Rust version.

Causes the JSON line emitted in the index to be invalid, presumably causing Cargo to skip over this version.

Sets the index schema version for this package.

See cargo::sources::registry::RegistryPackage for more information.

Creates the package and place it in the registry.

This does not actually use Cargo’s publishing system, but instead manually creates the entry in the registry on the filesystem.

Returns the checksum for the package.

Returns the path to the compressed package file.

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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 208 bytes