Skip to content

Commit 7cac565

Browse files
committed
refactor(util): Move VersionExt back into main cargo crate
This is a partial revert of 2b2502f These were pulled out with the idea of being a place to house `PartialVersion` for `util_schemas` to use. Since then, we went with a `util_schemas::core` in #13128, meaning we can hold off on creating yet another crate for us to manage.
1 parent 594e2be commit 7cac565

File tree

5 files changed

+28
-31
lines changed

5 files changed

+28
-31
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use anyhow::format_err;
66
use cargo::core::{GitReference, SourceId, Workspace};
77
use cargo::ops;
88
use cargo::util::IntoUrl;
9-
use cargo::util_semver::VersionExt;
9+
use cargo::util::VersionExt;
1010
use cargo::CargoResult;
1111
use itertools::Itertools;
1212
use semver::VersionReq;

src/cargo/core/resolver/errors.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use std::task::Poll;
44
use crate::core::{Dependency, PackageId, Registry, Summary};
55
use crate::sources::source::QueryKind;
66
use crate::util::edit_distance::edit_distance;
7-
use crate::util::{Config, OptVersionReq};
8-
use crate::util_semver::VersionExt;
7+
use crate::util::{Config, OptVersionReq, VersionExt};
98
use anyhow::Error;
109

1110
use super::context::Context;

src/cargo/util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub use self::lockserver::{LockServer, LockServerClient, LockServerStarted};
2222
pub use self::progress::{Progress, ProgressStyle};
2323
pub use self::queue::Queue;
2424
pub use self::rustc::Rustc;
25-
pub use self::semver_ext::OptVersionReq;
25+
pub use self::semver_ext::{OptVersionReq, VersionExt};
2626
pub use self::vcs::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
2727
pub use self::workspace::{
2828
add_path_args, path_args, print_available_benches, print_available_binaries,

src/cargo/util/semver_ext.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
use std::fmt::{self, Display};
22

3-
use semver::{Op, Version, VersionReq};
3+
use semver::{Comparator, Op, Version, VersionReq};
44

5-
use crate::util_semver::VersionExt as _;
5+
pub trait VersionExt {
6+
fn is_prerelease(&self) -> bool;
7+
8+
fn to_exact_req(&self) -> VersionReq;
9+
}
10+
11+
impl VersionExt for Version {
12+
fn is_prerelease(&self) -> bool {
13+
!self.pre.is_empty()
14+
}
15+
16+
fn to_exact_req(&self) -> VersionReq {
17+
VersionReq {
18+
comparators: vec![Comparator {
19+
op: Op::Exact,
20+
major: self.major,
21+
minor: Some(self.minor),
22+
patch: Some(self.patch),
23+
pre: self.pre.clone(),
24+
}],
25+
}
26+
}
27+
}
628

729
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
830
pub enum OptVersionReq {

src/cargo/util_semver.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,8 @@
11
use std::fmt::{self, Display};
22

3-
use semver::{Comparator, Op, Version, VersionReq};
3+
use semver::{Comparator, Version, VersionReq};
44
use serde_untagged::UntaggedEnumVisitor;
55

6-
pub trait VersionExt {
7-
fn is_prerelease(&self) -> bool;
8-
9-
fn to_exact_req(&self) -> VersionReq;
10-
}
11-
12-
impl VersionExt for Version {
13-
fn is_prerelease(&self) -> bool {
14-
!self.pre.is_empty()
15-
}
16-
17-
fn to_exact_req(&self) -> VersionReq {
18-
VersionReq {
19-
comparators: vec![Comparator {
20-
op: Op::Exact,
21-
major: self.major,
22-
minor: Some(self.minor),
23-
patch: Some(self.patch),
24-
pre: self.pre.clone(),
25-
}],
26-
}
27-
}
28-
}
29-
306
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug)]
317
pub struct PartialVersion {
328
pub major: u64,

0 commit comments

Comments
 (0)