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

Function format_hash

atomic-cli/src/commands/mod.rs:395–402  ·  view source on GitHub ↗

Format a hash for display. By default, hashes are truncated to [`DEFAULT_HASH_LENGTH`] characters for readability. Use `full = true` to show the complete hash. # Arguments `hash` - The hash to format `full` - Whether to show the full hash or truncate it # Returns A formatted string representation of the hash. # Example ```rust,ignore let hash = Hash::from_base32(b"ABCDEFGHIJKLMNOP").unwrap(

(hash: &Hash, full: bool)

Source from the content-addressed store, hash-verified

393/// println!("{}", format_hash(&hash, true)); // "ABCDEFGHIJKLMNOP"
394/// ```
395pub fn format_hash(hash: &Hash, full: bool) -> String {
396 let base32 = hash.to_base32();
397 if full || base32.len() <= DEFAULT_HASH_LENGTH {
398 base32
399 } else {
400 base32[..DEFAULT_HASH_LENGTH].to_string()
401 }
402}
403
404/// Format a hash for display with custom length.
405///

Callers 4

test_format_hash_fullFunction · 0.85
display_dry_runMethod · 0.85
display_dry_runMethod · 0.85

Calls 2

to_base32Method · 0.45
lenMethod · 0.45

Tested by 2

test_format_hash_fullFunction · 0.68