mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-11 16:34:33 +00:00
Split puffin-cache into Puffin-specific and generic utilities (#728)
This crate started off as generic caching utilities, but we started adding a lot of Puffin-specific stuff (like the cache buckets abstraction that knows about Git vs. direct URL vs. indexes and so on). This PR moves the generic stuff into a new `cache-key` crate.
This commit is contained in:
parent
4acf02f6b3
commit
6ff21374dc
27 changed files with 83 additions and 50 deletions
22
crates/cache-key/src/digest.rs
Normal file
22
crates/cache-key/src/digest.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use std::hash::Hasher;
|
||||
|
||||
use crate::cache_key::{CacheKey, CacheKeyHasher};
|
||||
|
||||
/// Compute a hex string hash of a `CacheKey` object.
|
||||
///
|
||||
/// The value returned by [`digest`] should be stable across releases and platforms.
|
||||
pub fn digest<H: CacheKey>(hashable: &H) -> String {
|
||||
to_hex(cache_key_u64(hashable))
|
||||
}
|
||||
|
||||
/// Convert a u64 to a hex string.
|
||||
fn to_hex(num: u64) -> String {
|
||||
hex::encode(num.to_le_bytes())
|
||||
}
|
||||
|
||||
/// Compute a u64 hash of a [`CacheKey`] object.
|
||||
fn cache_key_u64<H: CacheKey>(hashable: &H) -> u64 {
|
||||
let mut hasher = CacheKeyHasher::new();
|
||||
hashable.cache_key(&mut hasher);
|
||||
hasher.finish()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue