Skip to main content

fact_hash

Function fact_hash 

Source
pub fn fact_hash(fact: &Fact) -> Result<String, HashError>
Expand description

重导出 tier1 的哈希算法(单一真相源)

所有哈希计算函数均在 evorule_reactor::hash 中实现, 本模块通过 re-export 对外暴露相同的 API。 计算 Fact 的哈希(基于稳定的 JSON 序列化)

使用显式 JSON 序列化格式而非 Debug trait,确保序列化格式的稳定性。

§参数

  • fact: 要计算哈希的事实

§返回值

  • Ok(String): 64 字符的十六进制哈希字符串
  • Err(HashError): 哈希计算失败

§示例

use evorule_reactor::{Fact, FactId, fact_hash};
use evorule_tcb::JsonValue;

let fact = Fact::Command {
    id: FactId(1),
    instruction: JsonValue::empty_object(),
};
let hash = fact_hash(&fact).unwrap();
assert_eq!(hash.len(), 64);