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
Published package builder for TestRegistry
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 Package::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 Package::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.
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§
source§impl Package
impl Package
sourcepub fn new(name: &str, vers: &str) -> Package
pub fn new(name: &str, vers: &str) -> Package
Creates a new package builder.
Call publish()
to finalize and build the package.
sourcepub fn local(&mut self, local: bool) -> &mut Package
pub fn local(&mut self, local: bool) -> &mut 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.
sourcepub fn alternative(&mut self, alternative: bool) -> &mut Package
pub fn alternative(&mut self, alternative: bool) -> &mut Package
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.
Requires: alt_init
sourcepub fn file_with_mode(
&mut self,
path: &str,
mode: u32,
contents: &str,
) -> &mut Package
pub fn file_with_mode( &mut self, path: &str, mode: u32, contents: &str, ) -> &mut Package
Adds a file with a specific Unix mode.
sourcepub fn symlink(&mut self, dst: &str, src: &str) -> &mut Package
pub fn symlink(&mut self, dst: &str, src: &str) -> &mut Package
Adds a symlink to a path to the package.
sourcepub fn extra_file(&mut self, path: &str, contents: &str) -> &mut Package
pub fn extra_file(&mut self, path: &str, contents: &str) -> &mut 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.
sourcepub fn dep(&mut self, name: &str, vers: &str) -> &mut Package
pub fn dep(&mut self, name: &str, vers: &str) -> &mut Package
Adds a normal dependency. Example:
[dependencies]
foo = {version = "1.0"}
sourcepub fn feature_dep(
&mut self,
name: &str,
vers: &str,
features: &[&str],
) -> &mut Package
pub fn feature_dep( &mut self, name: &str, vers: &str, features: &[&str], ) -> &mut Package
Adds a dependency with the given feature. Example:
[dependencies]
foo = {version = "1.0", "features": ["feat1", "feat2"]}
sourcepub fn target_dep(
&mut self,
name: &str,
vers: &str,
target: &str,
) -> &mut Package
pub fn target_dep( &mut self, name: &str, vers: &str, target: &str, ) -> &mut Package
Adds a platform-specific dependency. Example:
[target.'cfg(windows)'.dependencies]
foo = {version = "1.0"}
sourcepub fn registry_dep(&mut self, name: &str, vers: &str) -> &mut Package
pub fn registry_dep(&mut self, name: &str, vers: &str) -> &mut Package
Adds a dependency to the alternative registry.
sourcepub fn dev_dep(&mut self, name: &str, vers: &str) -> &mut Package
pub fn dev_dep(&mut self, name: &str, vers: &str) -> &mut Package
Adds a dev-dependency. Example:
[dev-dependencies]
foo = {version = "1.0"}
sourcepub fn build_dep(&mut self, name: &str, vers: &str) -> &mut Package
pub fn build_dep(&mut self, name: &str, vers: &str) -> &mut Package
Adds a build-dependency. Example:
[build-dependencies]
foo = {version = "1.0"}
pub fn add_dep(&mut self, dep: &Dependency) -> &mut Package
sourcepub fn yanked(&mut self, yanked: bool) -> &mut Package
pub fn yanked(&mut self, yanked: bool) -> &mut Package
Specifies whether or not the package is “yanked”.
sourcepub fn proc_macro(&mut self, proc_macro: bool) -> &mut Package
pub fn proc_macro(&mut self, proc_macro: bool) -> &mut Package
Specifies whether or not this is a proc macro.
sourcepub fn feature(&mut self, name: &str, deps: &[&str]) -> &mut Package
pub fn feature(&mut self, name: &str, deps: &[&str]) -> &mut Package
Adds an entry in the [features]
section.
sourcepub fn rust_version(&mut self, rust_version: &str) -> &mut Package
pub fn rust_version(&mut self, rust_version: &str) -> &mut Package
Specify a minimal Rust version.
sourcepub fn invalid_json(&mut self, invalid: bool) -> &mut Package
pub fn invalid_json(&mut self, invalid: bool) -> &mut Package
Causes the JSON line emitted in the index to be invalid, presumably causing Cargo to skip over this version.
pub fn links(&mut self, links: &str) -> &mut Package
pub fn cargo_feature(&mut self, feature: &str) -> &mut Package
sourcepub fn schema_version(&mut self, version: u32) -> &mut Package
pub fn schema_version(&mut self, version: u32) -> &mut Package
Sets the index schema version for this package.
See cargo::sources::registry::IndexPackage
for more information.
sourcepub fn publish(&self) -> String
pub fn publish(&self) -> String
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.
fn make_archive(&self)
fn append_manifest<W: Write>(&self, ar: &mut Builder<W>)
fn append<W: Write>( &self, ar: &mut Builder<W>, file: &str, mode: u32, contents: &EntryData, )
fn append_raw<W: Write>( &self, ar: &mut Builder<W>, path: &str, mode: u32, contents: &EntryData, )
sourcepub fn archive_dst(&self) -> PathBuf
pub fn archive_dst(&self) -> PathBuf
Returns the path to the compressed package file.
Auto Trait Implementations§
impl Freeze for Package
impl RefUnwindSafe for Package
impl Send for Package
impl Sync for Package
impl Unpin for Package
impl UnwindSafe for Package
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
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