manual impl of hash

This commit is contained in:
Jacob Finkelman 2025-01-07 22:12:22 +00:00
parent d8b7c072c5
commit 06811d8594

View File

@ -1,7 +1,7 @@
use std::cmp::Ordering;
/// The possible kinds of code source.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SourceKind {
/// A git repository.
Git(GitReference),
@ -17,6 +17,19 @@ pub enum SourceKind {
Directory,
}
// The hash here is important for what folder packages get downloaded into.
// Changes trigger all users to download another copy of their crates.
// So the `stable_hash` test checks that we only change it intentionally.
// We implement hash manually to callout the stability impact.
impl std::hash::Hash for SourceKind {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
core::mem::discriminant(self).hash(state);
if let SourceKind::Git(git) = self {
git.hash(state);
}
}
}
impl SourceKind {
pub fn protocol(&self) -> Option<&str> {
match self {