MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / require

Method require

atomic-core/src/change/format_v3/hash_table.rs:330–334  ·  view source on GitHub ↗

Look up the index for a hash, returning an error if not found. This is a convenience method that wraps [`lookup`](Self::lookup) and converts `None` to [`FormatError::HashNotFound`]. # Arguments `hash` - The 32-byte hash to look up. # Errors - [`FormatError::HashNotFound`] if the hash isn't in the table. # Examples ```rust use atomic_core::change::format_v3::HashDedupTable; let self_hash =

(&self, hash: &[u8; 32])

Source from the content-addressed store, hash-verified

328 /// assert!(table.require(&[99u8; 32]).is_err());
329 /// ```
330 pub fn require(&self, hash: &[u8; 32]) -> FormatResult<HashIndex> {
331 self.lookup(hash).ok_or_else(|| FormatError::HashNotFound {
332 hash: data_encoding::BASE32_NOPAD.encode(&hash[..8]),
333 })
334 }
335
336 /// Resolve an index back to its 32-byte hash.
337 ///

Callers 6

runMethod · 0.45
runMethod · 0.45
runMethod · 0.45
test_require_missingFunction · 0.45
hash_to_indexMethod · 0.45

Calls 2

lookupMethod · 0.80
encodeMethod · 0.80

Tested by 2

test_require_missingFunction · 0.36