1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
use super::*; use std::cmp::Ordering; use std::fmt; #[derive(Debug, Eq)] pub struct AddressKey { pub value: [u8; 32], pub original: String, } impl Ord for AddressKey { fn cmp(&self, other: &Self) -> Ordering { self.original.cmp(&other.original) } } impl PartialOrd for AddressKey { fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) } } impl PartialEq for AddressKey { fn eq(&self, other: &Self) -> bool { self.original == other.original } } impl InterpretableFrom<String> for AddressKey { fn interpret_from(from: String, context: &InterpreterContext) -> Self { let bytes = interpret_string(from.as_str(), context); let mut value = [0u8; 32]; if bytes.len() == 32 { value.copy_from_slice(&bytes[..]); } AddressKey { value, original: from, } } } impl fmt::Display for AddressKey { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.original.fmt(f) } } #[derive(PartialEq, Clone, Debug)] pub struct AddressValue { pub value: [u8; 32], pub original: ValueSubTree, } impl InterpretableFrom<ValueSubTree> for AddressValue { fn interpret_from(from: ValueSubTree, context: &InterpreterContext) -> Self { let bytes = interpret_subtree(&from, context); let mut value = [0u8; 32]; if bytes.len() == 32 { value.copy_from_slice(&bytes[..]); } AddressValue { value, original: from, } } } impl fmt::Display for AddressValue { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.original.fmt(f) } }