Skip to main content

hash

Function hash 

Source
pub fn hash(value: &Value) -> String
Expand description

The digest of a value, as lowercase hexadecimal SHA-1.

The digest is stable across runs and machines for equal values. See the crate documentation for what equal means here.

ยงExample

use object_hash::{hash, Value};

let left = Value::Map(vec![
    ("b".into(), Value::number(2)),
    ("a".into(), Value::string("one")),
]);
// A map's key order does not change the digest.
let right = Value::Map(vec![
    ("a".into(), Value::string("one")),
    ("b".into(), Value::number(2)),
]);
assert_eq!(hash(&left), hash(&right));

// An array's order does.
assert_ne!(
    hash(&Value::Array(vec![Value::number(1), Value::number(2)])),
    hash(&Value::Array(vec![Value::number(2), Value::number(1)])),
);