mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Extract feature suffix formatting to function
This commit is contained in:
parent
e4de526f25
commit
c25bee16c9
@ -946,24 +946,7 @@ fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()>
|
|||||||
let (activated, deactivated) = dep.features();
|
let (activated, deactivated) = dep.features();
|
||||||
if !activated.is_empty() || !deactivated.is_empty() {
|
if !activated.is_empty() || !deactivated.is_empty() {
|
||||||
let prefix = format!("{:>13}", " ");
|
let prefix = format!("{:>13}", " ");
|
||||||
let suffix = if let Some(version) = &dep.available_version {
|
let suffix = format_feature_version_suffix(&dep);
|
||||||
let mut version = version.clone();
|
|
||||||
version.build = Default::default();
|
|
||||||
let version = version.to_string();
|
|
||||||
// Avoid displaying the version if it will visually look like the version req that we
|
|
||||||
// showed earlier
|
|
||||||
let version_req = dep
|
|
||||||
.version()
|
|
||||||
.and_then(|v| semver::VersionReq::parse(v).ok())
|
|
||||||
.and_then(|v| precise_version(&v));
|
|
||||||
if version_req.as_deref() != Some(version.as_str()) {
|
|
||||||
format!(" as of v{version}")
|
|
||||||
} else {
|
|
||||||
"".to_owned()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
"".to_owned()
|
|
||||||
};
|
|
||||||
|
|
||||||
shell.write_stderr(format_args!("{}Features{}:\n", prefix, suffix), &style::NOP)?;
|
shell.write_stderr(format_args!("{}Features{}:\n", prefix, suffix), &style::NOP)?;
|
||||||
|
|
||||||
@ -1009,6 +992,27 @@ fn print_dep_table_msg(shell: &mut Shell, dep: &DependencyUI) -> CargoResult<()>
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn format_feature_version_suffix(dep: &DependencyUI) -> String {
|
||||||
|
if let Some(version) = &dep.available_version {
|
||||||
|
let mut version = version.clone();
|
||||||
|
version.build = Default::default();
|
||||||
|
let version = version.to_string();
|
||||||
|
// Avoid displaying the version if it will visually look like the version req that we
|
||||||
|
// showed earlier
|
||||||
|
let version_req = dep
|
||||||
|
.version()
|
||||||
|
.and_then(|v| semver::VersionReq::parse(v).ok())
|
||||||
|
.and_then(|v| precise_version(&v));
|
||||||
|
if version_req.as_deref() != Some(version.as_str()) {
|
||||||
|
format!(" as of v{version}")
|
||||||
|
} else {
|
||||||
|
"".to_owned()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
"".to_owned()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Based on Iterator::is_sorted from nightly std; remove in favor of that when stabilized.
|
// Based on Iterator::is_sorted from nightly std; remove in favor of that when stabilized.
|
||||||
fn is_sorted(mut it: impl Iterator<Item = impl PartialOrd>) -> bool {
|
fn is_sorted(mut it: impl Iterator<Item = impl PartialOrd>) -> bool {
|
||||||
let Some(mut last) = it.next() else {
|
let Some(mut last) = it.next() else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user