Skip to main content

bibliography_content_hash

Function bibliography_content_hash 

Source
pub fn bibliography_content_hash(bytes: &[u8]) -> ContentHash
Expand description

Compute the content-hash boundary for one bibliography source’s raw bytes.

The result is the §4.1 source hash specialized to bibliography inputs: deterministic for identical bytes, divergent for any byte change, and independent of where or when the file was read. Pair it with a mos_cache::DependencyId::Bibliography identity (typically via mos_cache::BibliographyDependency) to model a full bibliography dependency.

§Examples

Identical bytes hash equal; a one-byte edit diverges:

use mos_bib::bibliography_content_hash;

let a = bibliography_content_hash(b"@article{k, year = 1984}");
let b = bibliography_content_hash(b"@article{k, year = 1984}");
assert_eq!(a, b);
assert_ne!(a, bibliography_content_hash(b"@article{k, year = 1985}"));

Hashing is byte-for-byte, so NFC- and NFD-encoded text that looks the same produces different hashes (the parser sees different bytes, §4.1):

use mos_bib::bibliography_content_hash;

// "é" composed (NFC) vs. "e" + combining acute (NFD).
let nfc = bibliography_content_hash("@misc{r, note = {\u{00e9}}}".as_bytes());
let nfd = bibliography_content_hash("@misc{r, note = {e\u{0301}}}".as_bytes());
assert_ne!(nfc, nfd);