-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
42 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::num::NonZeroU64; | ||
|
||
use crate::core::SourceId; | ||
use crate::util::interning::InternedString; | ||
|
||
/// Find the activated version of a crate based on the name, source, and semver compatibility. | ||
/// By storing this in a hash map we ensure that there is only one | ||
/// semver compatible version of each crate. | ||
/// This all so stores the `ContextAge`. | ||
pub type ActivationsKey = (InternedString, SourceId, SemverCompatibility); | ||
|
||
/// A type that represents when cargo treats two Versions as compatible. | ||
/// Versions `a` and `b` are compatible if their left-most nonzero digit is the | ||
/// same. | ||
#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug, PartialOrd, Ord)] | ||
pub enum SemverCompatibility { | ||
Major(NonZeroU64), | ||
Minor(NonZeroU64), | ||
Patch(u64), | ||
} | ||
|
||
impl From<&semver::Version> for SemverCompatibility { | ||
fn from(ver: &semver::Version) -> Self { | ||
if let Some(m) = NonZeroU64::new(ver.major) { | ||
return SemverCompatibility::Major(m); | ||
} | ||
if let Some(m) = NonZeroU64::new(ver.minor) { | ||
return SemverCompatibility::Minor(m); | ||
} | ||
SemverCompatibility::Patch(ver.patch) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters