# Struct cargo::core::dependency::Dependency

source ·

    pub struct Dependency {
        inner: Rc<Inner>,
    }

Expand description

Information about a dependency requested by a Cargo manifest. Cheap to copy.

## Fields§

§`inner: Rc<Inner>`

## Implementations§

source§

### impl Dependency

source

#### pub fn parse( name: impl Into<InternedString>, version: Option<&str>, source_id: SourceId ) -> CargoResult<Dependency>

Attempt to create a `Dependency` from an entry in the manifest.

source

#### pub fn new_override(name: InternedString, source_id: SourceId) -> Dependency

source

#### pub fn version_req(&self) -> &OptVersionReq

source

#### pub fn name_in_toml(&self) -> InternedString

This is the name of this `Dependency` as listed in `Cargo.toml`.

Or in other words, this is what shows up in the `[dependencies]` section on the left hand side. This is not the name of the package that’s being depended on as the dependency can be renamed. For that use `package_name` below.

Both of the dependencies below return `foo` for `name_in_toml`:

    [dependencies]
    foo = "0.1"

and …

    [dependencies]
    foo = { version = "0.1", package = 'bar' }

source

#### pub fn package_name(&self) -> InternedString

The name of the package that this `Dependency` depends on.

Usually this is what’s written on the left hand side of a dependencies section, but it can also be renamed via the `package` key.

Both of the dependencies below return `foo` for `package_name`:

    [dependencies]
    foo = "0.1"

and …

    [dependencies]
    bar = { version = "0.1", package = 'foo' }

source

#### pub fn source_id(&self) -> SourceId

source

#### pub fn registry_id(&self) -> Option<SourceId>

source

#### pub fn set_registry_id(&mut self, registry_id: SourceId) -> &mut Dependency

source

#### pub fn kind(&self) -> DepKind

source

#### pub fn is_public(&self) -> bool

source

#### pub fn set_public(&mut self, public: bool) -> &mut Dependency

Sets whether the dependency is public.

source

#### pub fn specified_req(&self) -> bool

source

#### pub fn platform(&self) -> Option<&Platform>

If none, this dependencies must be built for all platforms. If some, it must only be built for the specified platform.

source

#### pub fn explicit_name_in_toml(&self) -> Option<InternedString>

The renamed name of this dependency, if any.

If the `package` key is used in `Cargo.toml` then this returns the same value as `name_in_toml`.

source

#### pub fn set_kind(&mut self, kind: DepKind) -> &mut Dependency

source

#### pub fn set_features( &mut self, features: impl IntoIterator<Item = impl Into<InternedString>> ) -> &mut Dependency

Sets the list of features requested for the package.

source

#### pub fn set_default_features( &mut self, default_features: bool ) -> &mut Dependency

Sets whether the dependency requests default features of the package.

source

#### pub fn set_optional(&mut self, optional: bool) -> &mut Dependency

Sets whether the dependency is optional.

source

#### pub fn set_source_id(&mut self, id: SourceId) -> &mut Dependency

Sets the source ID for this dependency.

source

#### pub fn set_version_req(&mut self, req: OptVersionReq) -> &mut Dependency

Sets the version requirement for this dependency.

source

#### pub fn set_platform(&mut self, platform: Option<Platform>) -> &mut Dependency

source

#### pub fn set_explicit_name_in_toml( &mut self, name: impl Into<InternedString> ) -> &mut Dependency

source

#### pub fn lock_to(&mut self, id: PackageId) -> &mut Dependency

Locks this dependency to depending on the specified package ID.

source

#### pub fn lock_version(&mut self, version: &Version) -> &mut Dependency

Locks this dependency to a specified version.

Mainly used in dependency patching like `[patch]` or `[replace]`, which doesn’t need to lock the entire dependency to a specific `PackageId`.

source

#### pub fn is_locked(&self) -> bool

Returns `true` if this is a “locked” dependency. Basically a locked dependency has an exact version req, but not vice versa.

source

#### pub fn is_transitive(&self) -> bool

Returns `false` if the dependency is only used to build the local package.

source

#### pub fn is_build(&self) -> bool

source

#### pub fn is_optional(&self) -> bool

source

#### pub fn uses_default_features(&self) -> bool

Returns `true` if the default features of the dependency are requested.

source

#### pub fn features(&self) -> &[InternedString]

Returns the list of features that are requested by the dependency.

source

#### pub fn matches(&self, sum: &Summary) -> bool

Returns `true` if the package (`sum`) can fulfill this dependency request.

source

#### pub fn matches_ignoring_source(&self, id: PackageId) -> bool

Returns `true` if the package (`id`) can fulfill this dependency request.

source

#### pub fn matches_id(&self, id: PackageId) -> bool

Returns `true` if the package (`id`) can fulfill this dependency request.

source

#### pub fn map_source( self, to_replace: SourceId, replace_with: SourceId ) -> Dependency

source

#### pub(crate) fn set_artifact(&mut self, artifact: Artifact)

source

#### pub(crate) fn artifact(&self) -> Option<&Artifact>

source

#### pub(crate) fn maybe_lib(&self) -> bool

Dependencies are potential rust libs if they are not artifacts or they are an artifact which allows to be seen as library. Previously, every dependency was potentially seen as library.

## Trait Implementations§

source§

### impl Clone for Dependency

source§

#### fn clone(&self) -> Dependency

Returns a copy of the value. Read more
1.0.0 · source§

#### fn clone_from(&mut self, source: &Self)

Performs copy-assignment from `source`. Read more
source§

### impl Debug for Dependency

source§

#### fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

### impl Hash for Dependency

source§

#### fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given `Hasher`. Read more
1.3.0 · source§

#### fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given `Hasher`. Read more
source§

### impl PartialEq for Dependency

source§

#### fn eq(&self, other: &Dependency) -> bool

This method tests for `self` and `other` values to be equal, and is used by `==`.
1.0.0 · source§

#### fn ne(&self, other: &Rhs) -> bool

This method tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

### impl Serialize for Dependency

source§

#### fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

### impl Eq for Dependency

source§

### impl StructuralPartialEq for Dependency

## Auto Trait Implementations§

§

### impl RefUnwindSafe for Dependency

§

### impl !Send for Dependency

§

### impl !Sync for Dependency

§

### impl Unpin for Dependency

§

### impl UnwindSafe for Dependency

## 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
§

### impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

#### fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

### impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

#### fn equivalent(&self, key: &K) -> bool

Compare self to `key` and return `true` if they are equal.
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

§

#### type Output = T

Should always be `Self`
source§

### impl<T> Serialize for T
where T: Serialize + ?Sized,

source§

#### fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

source§

#### fn do_erased_serialize(&self, serializer: &mut dyn Serializer)

source§

### impl<T> ToOwned for T
where T: Clone,

§

#### type Owned = T

The resulting type after obtaining ownership.
source§

#### fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

#### fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

#### 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>,

§

#### 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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

#### fn vzip(self) -> V

§

### 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: 8 bytes