Skip to content

Commit fa76b63

Browse files
committed
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 <[email protected]>
1 parent 708383d commit fa76b63

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/cargo/ops/cargo_add/mod.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use crate::util::toml_mut::dependency::MaybeWorkspace;
3131
use crate::util::toml_mut::dependency::PathSource;
3232
use crate::util::toml_mut::dependency::Source;
3333
use crate::util::toml_mut::dependency::WorkspaceSource;
34+
use crate::util::toml_mut::is_sorted;
3435
use crate::util::toml_mut::manifest::DepTable;
3536
use crate::util::toml_mut::manifest::LocalManifest;
3637
use crate::util::RustVersion;
@@ -1004,22 +1005,6 @@ fn format_features_version_suffix(dep: &DependencyUI) -> String {
10041005
}
10051006
}
10061007

1007-
// Based on Iterator::is_sorted from nightly std; remove in favor of that when stabilized.
1008-
fn is_sorted(mut it: impl Iterator<Item = impl PartialOrd>) -> bool {
1009-
let Some(mut last) = it.next() else {
1010-
return true;
1011-
};
1012-
1013-
for curr in it {
1014-
if curr < last {
1015-
return false;
1016-
}
1017-
last = curr;
1018-
}
1019-
1020-
true
1021-
}
1022-
10231008
fn find_workspace_dep(toml_key: &str, root_manifest: &Path) -> CargoResult<Dependency> {
10241009
let manifest = LocalManifest::try_new(root_manifest)?;
10251010
let manifest = manifest

src/cargo/util/toml_mut/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,19 @@
1111
1212
pub mod dependency;
1313
pub mod manifest;
14+
15+
// Based on Iterator::is_sorted from nightly std; remove in favor of that when stabilized.
16+
pub fn is_sorted(mut it: impl Iterator<Item = impl PartialOrd>) -> bool {
17+
let Some(mut last) = it.next() else {
18+
return true;
19+
};
20+
21+
for curr in it {
22+
if curr < last {
23+
return false;
24+
}
25+
last = curr;
26+
}
27+
28+
true
29+
}

0 commit comments

Comments
 (0)