cargo_test_support::registry

Struct Package

source
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

source

pub fn new(name: &str, vers: &str) -> Package

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

source

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.

source

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

source

pub fn file(&mut self, name: &str, contents: &str) -> &mut Package

Adds a file to the package.

source

pub fn file_with_mode( &mut self, path: &str, mode: u32, contents: &str, ) -> &mut Package

Adds a file with a specific Unix mode.

Adds a symlink to a path to the package.

source

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.

source

pub fn dep(&mut self, name: &str, vers: &str) -> &mut Package

Adds a normal dependency. Example:

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

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"]}
source

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"}
source

pub fn registry_dep(&mut self, name: &str, vers: &str) -> &mut Package

Adds a dependency to the alternative registry.

source

pub fn dev_dep(&mut self, name: &str, vers: &str) -> &mut Package

Adds a dev-dependency. Example:

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

pub fn build_dep(&mut self, name: &str, vers: &str) -> &mut Package

Adds a build-dependency. Example:

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

pub fn add_dep(&mut self, dep: &Dependency) -> &mut Package

source

pub fn yanked(&mut self, yanked: bool) -> &mut Package

Specifies whether or not the package is “yanked”.

source

pub fn proc_macro(&mut self, proc_macro: bool) -> &mut Package

Specifies whether or not this is a proc macro.

source

pub fn feature(&mut self, name: &str, deps: &[&str]) -> &mut Package

Adds an entry in the [features] section.

source

pub fn rust_version(&mut self, rust_version: &str) -> &mut Package

Specify a minimal Rust version.

source

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.

source

pub fn cargo_feature(&mut self, feature: &str) -> &mut Package

source

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.

source

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.

source

fn make_archive(&self)

source

fn append_manifest<W: Write>(&self, ar: &mut Builder<W>)

source

fn append<W: Write>( &self, ar: &mut Builder<W>, file: &str, mode: u32, contents: &EntryData, )

source

fn append_raw<W: Write>( &self, ar: &mut Builder<W>, path: &str, mode: u32, contents: &EntryData, )

source

pub fn archive_dst(&self) -> PathBuf

Returns the path to the compressed package file.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

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