Struct guppy::graph::summaries::PackageSetSummary
source · pub struct PackageSetSummary {
pub summary_ids: BTreeSet<SummaryId>,
pub workspace_members: BTreeSet<String>,
pub third_party: Vec<ThirdPartySummary>,
}
summaries
only.Expand description
A set of packages specified in a summary. Can be resolved into a PackageSet
given a
PackageGraph
.
Requires the summaries
feature to be enabled.
Examples
Parsing a summary from a TOML specification, as found in e.g. a config file.
// This is an example TOML config for a PackageSet resolved from this workspace.
static TOML_INPUT: &str = r#"
workspace-members = ["guppy", "target-spec"]
# The version field specifies a range, just like Cargo.
# Third-party specifications also include "git" and "path".
third-party = [
{ name = "serde", version = "*" },
{ name = "rayon", version = "1.5" },
]
"#;
let summary: PackageSetSummary = toml::from_str(TOML_INPUT).expect("input parsed correctly");
let graph = MetadataCommand::new().build_graph().expect("guppy graph constructed");
let package_set = summary
.to_package_set(&graph, "resolving example TOML")
.expect("all elements matched");
let package_names: HashSet<_> = package_set
.packages(DependencyDirection::Forward)
.map(|metadata| metadata.name())
.collect();
let mut expected_names = HashSet::new();
expected_names.extend(["guppy", "target-spec", "serde", "rayon"]);
assert_eq!(package_names, expected_names, "package names matched");
Specifying an invalid package results in an error.
// This is an example TOML config that contains package names that are unknown to this
// workspace.
static UNKNOWN_TOML_INPUT: &str = r#"
# serde is a third-party dependency, so it won't be matched in workspace-members.
workspace-members = ["unknown-member", "serde"]
# guppy is a workspace dependency, so it won't be matched in workspace-members.
# serde is present but the version number doesn't match.
third-party = [
{ name = "guppy" },
{ name = "serde", version = "0.9" },
{ name = "unknown-third-party" },
]
"#;
let summary: PackageSetSummary = toml::from_str(UNKNOWN_TOML_INPUT).expect("input parsed correctly");
let graph = MetadataCommand::new().build_graph().expect("guppy graph constructed");
let err = summary
.to_package_set(&graph, "resolving example TOML")
.expect_err("some elements are unknown");
assert_eq!(
format!("{}", err),
r#"unknown elements: resolving example TOML
* unknown workspace names:
- serde
- unknown-member
* unknown third-party:
- { name = "guppy", version = "*", source = crates.io }
- { name = "serde", version = "^0.9", source = crates.io }
- { name = "unknown-third-party", version = "*", source = crates.io }
"#
);
Fields§
§summary_ids: BTreeSet<SummaryId>
A set of summary identifiers. Typically used in generated summaries.
Does not require a PackageGraph
as context.
workspace_members: BTreeSet<String>
Workspace packages, specified by names. Typically used in config files.
These require a PackageGraph
as context.
third_party: Vec<ThirdPartySummary>
Non-workspace packages, including non-workspace path dependencies. Typically used in config files.
Requires a PackageGraph
as context.
Implementations§
source§impl PackageSetSummary
impl PackageSetSummary
sourcepub fn new(package_set: &PackageSet<'_>) -> Self
pub fn new(package_set: &PackageSet<'_>) -> Self
Constructs a PackageSetSummary
from a PackageSet
.
sourcepub fn from_package_ids<'a>(
graph: &PackageGraph,
package_ids: impl IntoIterator<Item = &'a PackageId>
) -> Result<Self, Error>
pub fn from_package_ids<'a>( graph: &PackageGraph, package_ids: impl IntoIterator<Item = &'a PackageId> ) -> Result<Self, Error>
Constructs a PackageSetSummary
from an iterator of PackageId
s.
sourcepub fn to_package_set<'g>(
&self,
graph: &'g PackageGraph,
error_message: impl Into<String>
) -> Result<PackageSet<'g>, Error>
pub fn to_package_set<'g>( &self, graph: &'g PackageGraph, error_message: impl Into<String> ) -> Result<PackageSet<'g>, Error>
Converts this PackageSetSummary
to a PackageSet
.
Returns an error if any of the elements weren’t matched.
sourcepub fn to_package_set_registry<'g, 'a>(
&'a self,
graph: &'g PackageGraph,
registry_name_to_url: impl FnMut(&str) -> Option<&'a str>,
error_message: impl Into<String>
) -> Result<PackageSet<'g>, Error>
pub fn to_package_set_registry<'g, 'a>( &'a self, graph: &'g PackageGraph, registry_name_to_url: impl FnMut(&str) -> Option<&'a str>, error_message: impl Into<String> ) -> Result<PackageSet<'g>, Error>
Converts this PackageSetSummary
to a PackageSet
, with the given source for registry
names.
Returns an error if any of the elements weren’t matched.
This is a temporary workaround until Cargo issue #9052 is resolved.
Trait Implementations§
source§impl Clone for PackageSetSummary
impl Clone for PackageSetSummary
source§fn clone(&self) -> PackageSetSummary
fn clone(&self) -> PackageSetSummary
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PackageSetSummary
impl Debug for PackageSetSummary
source§impl Default for PackageSetSummary
impl Default for PackageSetSummary
source§fn default() -> PackageSetSummary
fn default() -> PackageSetSummary
source§impl<'de> Deserialize<'de> for PackageSetSummary
impl<'de> Deserialize<'de> for PackageSetSummary
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl PartialEq<PackageSetSummary> for PackageSetSummary
impl PartialEq<PackageSetSummary> for PackageSetSummary
source§fn eq(&self, other: &PackageSetSummary) -> bool
fn eq(&self, other: &PackageSetSummary) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for PackageSetSummary
impl Serialize for PackageSetSummary
impl Eq for PackageSetSummary
impl StructuralEq for PackageSetSummary
impl StructuralPartialEq for PackageSetSummary
Auto Trait Implementations§
impl RefUnwindSafe for PackageSetSummary
impl Send for PackageSetSummary
impl Sync for PackageSetSummary
impl Unpin for PackageSetSummary
impl UnwindSafe for PackageSetSummary
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
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.