pub struct Hash(/* private fields */);Expand description
Re-exports of the core data structures.
§Purpose
All version-control objects (Blob, Tree, Commit, Tag) and
their supporting types are available directly from the crate root for
ergonomic access.
§Examples
use libvctrl::Blob;
let blob = Blob::new(vec![1, 2, 3]);
assert_eq!(blob.size(), 3);A 64-byte cryptographic hash used to identify version control objects.
§Purpose
This type represents the output of a 512-bit hash function (like SHA-512).
It is used to address and retrieve objects in the
ObjectStore.
§Design rationale
By wrapping the byte array in a tuple struct, we prevent type confusion
with other 64-byte arrays. The inner array is private to ensure it can
only be constructed via Hash::from_bytes,
which enforces the length invariant.
§Examples
use libvctrl_handler::Hash;
let bytes = [0u8; 64];
let hash = Hash::from_bytes(&bytes).unwrap();
assert_eq!(hash.as_bytes(), &bytes);Implementations§
Source§impl Hash
impl Hash
Sourcepub const fn from_bytes(bytes: &[u8]) -> Result<Hash, VctrlError>
pub const fn from_bytes(bytes: &[u8]) -> Result<Hash, VctrlError>
Creates a Hash from a slice of bytes.
§Design rationale
This is a const fn to allow compile-time construction of hashes. The
while loop is used because for loops and slice iterators were
historically not stable in const contexts.
§Errors
Returns VctrlError::InvalidHashLength
if the length of bytes is not exactly
HASH_LENGTH.
§Examples
use libvctrl_handler::{Hash, VctrlError};
let valid = Hash::from_bytes(&[0u8; 64]);
assert!(valid.is_ok());
let invalid = Hash::from_bytes(&[0u8; 32]);
assert!(matches!(invalid, Err(VctrlError::InvalidHashLength(32))));Trait Implementations§
impl Copy for Hash
Source§impl Debug for Hash
Formats the hash for debugging purposes.
impl Debug for Hash
Formats the hash for debugging purposes.
§Design rationale
The default Debug implementation for arrays would print all 64 bytes,
which clutters log output. This implementation prints only the first 8
bytes (16 hex characters) followed by an ellipsis, which is sufficient to
distinguish between different hashes in logs.
§Examples
use libvctrl_handler::Hash;
let bytes = [0u8; 64];
let hash = Hash::from_bytes(&bytes).unwrap();
assert_eq!(format!("{hash:?}"), "Hash(0000000000000000…)");Source§impl Display for Hash
Formats the hash as a lowercase hexadecimal string.
impl Display for Hash
Formats the hash as a lowercase hexadecimal string.
§Design rationale
Hexadecimal is the standard representation for cryptographic hashes in version control systems (e.g., Git object IDs). This implementation is zero-allocation and writes directly to the formatter.
§Examples
use libvctrl_handler::Hash;
let bytes = [0u8; 64];
let hash = Hash::from_bytes(&bytes).unwrap();
assert_eq!(format!("{hash}"), "00".repeat(64));