mirror of
https://github.com/rust-lang/cargo
synced 2024-08-28 03:39:31 +00:00
Move is_sorted
to a shared package.
This function can be used by other commands to figure out whether a list is sorted or not. Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
708383d620
commit
fa76b63ce9
|
@ -31,6 +31,7 @@ use crate::util::toml_mut::dependency::MaybeWorkspace;
|
|||
use crate::util::toml_mut::dependency::PathSource;
|
||||
use crate::util::toml_mut::dependency::Source;
|
||||
use crate::util::toml_mut::dependency::WorkspaceSource;
|
||||
use crate::util::toml_mut::is_sorted;
|
||||
use crate::util::toml_mut::manifest::DepTable;
|
||||
use crate::util::toml_mut::manifest::LocalManifest;
|
||||
use crate::util::RustVersion;
|
||||
|
@ -1004,22 +1005,6 @@ fn format_features_version_suffix(dep: &DependencyUI) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
let Some(mut last) = it.next() else {
|
||||
return true;
|
||||
};
|
||||
|
||||
for curr in it {
|
||||
if curr < last {
|
||||
return false;
|
||||
}
|
||||
last = curr;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
fn find_workspace_dep(toml_key: &str, root_manifest: &Path) -> CargoResult<Dependency> {
|
||||
let manifest = LocalManifest::try_new(root_manifest)?;
|
||||
let manifest = manifest
|
||||
|
|
|
@ -11,3 +11,19 @@
|
|||
|
||||
pub mod dependency;
|
||||
pub mod manifest;
|
||||
|
||||
// Based on Iterator::is_sorted from nightly std; remove in favor of that when stabilized.
|
||||
pub fn is_sorted(mut it: impl Iterator<Item = impl PartialOrd>) -> bool {
|
||||
let Some(mut last) = it.next() else {
|
||||
return true;
|
||||
};
|
||||
|
||||
for curr in it {
|
||||
if curr < last {
|
||||
return false;
|
||||
}
|
||||
last = curr;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue