1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
denoland-deno/cli/cache/common.rs
Bartek Iwańczuk 2bb013f9ba
refactor: version module exports a single const struct (#25014)
This commit rewrites the internal `version` module that exported
various information about the current executable. Instead of exporting
several consts, we are now exporting a single const structure that 
contains all the necessary information.

This is the first step towards cleaning up how we use this information
and should allow us to use SUI to be able to patch this information
in already produced binary making it easier to cut new releases.

---------

Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
2024-08-15 23:47:16 +02:00

50 lines
1.1 KiB
Rust

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use std::hash::Hasher;
/// A very fast insecure hasher that uses the xxHash algorithm.
pub struct FastInsecureHasher(twox_hash::XxHash64);
impl FastInsecureHasher {
pub fn new_without_deno_version() -> Self {
Self(Default::default())
}
pub fn new_deno_versioned() -> Self {
let mut hasher = Self::new_without_deno_version();
hasher.write_str(crate::version::DENO_VERSION_INFO.deno);
hasher
}
pub fn write_str(&mut self, text: &str) -> &mut Self {
self.write(text.as_bytes());
self
}
pub fn write(&mut self, bytes: &[u8]) -> &mut Self {
self.0.write(bytes);
self
}
pub fn write_u8(&mut self, value: u8) -> &mut Self {
self.0.write_u8(value);
self
}
pub fn write_u64(&mut self, value: u64) -> &mut Self {
self.0.write_u64(value);
self
}
pub fn write_hashable(
&mut self,
hashable: impl std::hash::Hash,
) -> &mut Self {
hashable.hash(&mut self.0);
self
}
pub fn finish(&self) -> u64 {
self.0.finish()
}
}