Struct cargo::core::dependency::Dependency
source · pub struct Dependency { /* private fields */ }
Expand description
Information about a dependency requested by a Cargo manifest. Cheap to copy.
Implementations
sourceimpl Dependency
impl Dependency
sourcepub fn parse(
name: &str,
version: Option<&str>,
source_id: &SourceId,
inside: &PackageId,
config: &Config
) -> CargoResult<Dependency>
pub fn parse(
name: &str,
version: Option<&str>,
source_id: &SourceId,
inside: &PackageId,
config: &Config
) -> CargoResult<Dependency>
Attempt to create a Dependency
from an entry in the manifest.
sourcepub fn parse_no_deprecated(
name: &str,
version: Option<&str>,
source_id: &SourceId
) -> CargoResult<Dependency>
pub fn parse_no_deprecated(
name: &str,
version: Option<&str>,
source_id: &SourceId
) -> CargoResult<Dependency>
Attempt to create a Dependency
from an entry in the manifest.
pub fn new_override(name: &str, source_id: &SourceId) -> Dependency
pub fn version_req(&self) -> &VersionReq
sourcepub fn name_in_toml(&self) -> InternedString
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' }
sourcepub fn package_name(&self) -> InternedString
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' }
pub fn source_id(&self) -> &SourceId
pub fn registry_id(&self) -> Option<&SourceId>
pub fn set_registry_id(&mut self, registry_id: &SourceId) -> &mut Dependency
pub fn kind(&self) -> Kind
pub fn specified_req(&self) -> bool
sourcepub fn platform(&self) -> Option<&Platform>
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.
sourcepub fn rename(&self) -> Option<InternedString>
pub fn rename(&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
.
pub fn set_kind(&mut self, kind: Kind) -> &mut Dependency
sourcepub fn set_features(
&mut self,
features: impl IntoIterator<Item = impl AsRef<str>>
) -> &mut Dependency
pub fn set_features(
&mut self,
features: impl IntoIterator<Item = impl AsRef<str>>
) -> &mut Dependency
Sets the list of features requested for the package.
sourcepub fn set_default_features(&mut self, default_features: bool) -> &mut Dependency
pub fn set_default_features(&mut self, default_features: bool) -> &mut Dependency
Sets whether the dependency requests default features of the package.
sourcepub fn set_optional(&mut self, optional: bool) -> &mut Dependency
pub fn set_optional(&mut self, optional: bool) -> &mut Dependency
Sets whether the dependency is optional.
sourcepub fn set_source_id(&mut self, id: SourceId) -> &mut Dependency
pub fn set_source_id(&mut self, id: SourceId) -> &mut Dependency
Set the source id for this dependency
sourcepub fn set_version_req(&mut self, req: VersionReq) -> &mut Dependency
pub fn set_version_req(&mut self, req: VersionReq) -> &mut Dependency
Set the version requirement for this dependency
pub fn set_platform(&mut self, platform: Option<Platform>) -> &mut Dependency
pub fn set_rename(&mut self, rename: &str) -> &mut Dependency
sourcepub fn lock_to(&mut self, id: &PackageId) -> &mut Dependency
pub fn lock_to(&mut self, id: &PackageId) -> &mut Dependency
Lock this dependency to depending on the specified package id
sourcepub fn is_locked(&self) -> bool
pub fn is_locked(&self) -> bool
Returns whether this is a “locked” dependency, basically whether it has an exact version req.
sourcepub fn is_transitive(&self) -> bool
pub fn is_transitive(&self) -> bool
Returns false if the dependency is only used to build the local package.
pub fn is_build(&self) -> bool
pub fn is_optional(&self) -> bool
sourcepub fn uses_default_features(&self) -> bool
pub fn uses_default_features(&self) -> bool
Returns true if the default features of the dependency are requested.
sourcepub fn features(&self) -> &[InternedString]
pub fn features(&self) -> &[InternedString]
Returns the list of features that are requested by the dependency.
sourcepub fn matches(&self, sum: &Summary) -> bool
pub fn matches(&self, sum: &Summary) -> bool
Returns true if the package (sum
) can fulfill this dependency request.
sourcepub fn matches_ignoring_source(&self, id: &PackageId) -> bool
pub fn matches_ignoring_source(&self, id: &PackageId) -> bool
Returns true if the package (sum
) can fulfill this dependency request.
sourcepub fn matches_id(&self, id: &PackageId) -> bool
pub fn matches_id(&self, id: &PackageId) -> bool
Returns true if the package (id
) can fulfill this dependency request.
pub fn map_source(
self,
to_replace: &SourceId,
replace_with: &SourceId
) -> Dependency
Trait Implementations
sourceimpl Clone for Dependency
impl Clone for Dependency
sourcefn clone(&self) -> Dependency
fn clone(&self) -> Dependency
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl Debug for Dependency
impl Debug for Dependency
sourceimpl Hash for Dependency
impl Hash for Dependency
sourceimpl Ord for Dependency
impl Ord for Dependency
sourcefn cmp(&self, other: &Dependency) -> Ordering
fn cmp(&self, other: &Dependency) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl PartialEq<Dependency> for Dependency
impl PartialEq<Dependency> for Dependency
sourcefn eq(&self, other: &Dependency) -> bool
fn eq(&self, other: &Dependency) -> bool
sourceimpl PartialOrd<Dependency> for Dependency
impl PartialOrd<Dependency> for Dependency
sourcefn partial_cmp(&self, other: &Dependency) -> Option<Ordering>
fn partial_cmp(&self, other: &Dependency) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more