| 735 | |
| 736 | /// A dynamically-typed value stored in expression metadata (`KVMap` entries). |
| 737 | #[derive(Debug, PartialEq, Eq, Clone, Hash)] |
| 738 | pub enum DataValue { |
| 739 | /// A string value. |
| 740 | OfString(String), |
| 741 | /// A boolean value. |
| 742 | OfBool(bool), |
| 743 | /// A name value. |
| 744 | OfName(Name), |
| 745 | /// A natural number value. |
| 746 | OfNat(Nat), |
| 747 | /// An integer value. |
| 748 | OfInt(Int), |
| 749 | /// A syntax tree value. |
| 750 | OfSyntax(Box<Syntax>), |
| 751 | } |
| 752 | |
| 753 | pub fn hash_data_value(dv: &DataValue, hasher: &mut blake3::Hasher) { |
| 754 | hasher.update(&[MDVAL]); |
| 755 | match dv { |
| 756 | DataValue::OfString(s) => { |
| 757 | hasher.update(&[0]); |
| 758 | hasher.update(s.as_bytes()); |
| 759 | }, |
| 760 | DataValue::OfBool(b) => { |
| 761 | hasher.update(&[1]); |
| 762 | hasher.update(&[u8::from(*b)]); |
| 763 | }, |
| 764 | DataValue::OfName(name) => { |
| 765 | hasher.update(&[2]); |
| 766 | hasher.update(name.get_hash().as_bytes()); |
| 767 | }, |
| 768 | DataValue::OfNat(n) => { |