Assorted tweaks to support external playground crate (#322)

* Assorted tweaks to support external playground crate

* Fix schemas

* Fixed schema again

* Add ToHex for RawValue

* Add FromHex to RawValue
This commit is contained in:
Rob Knight 2025-07-02 18:27:54 +02:00 committed by GitHub
parent 335100d1d7
commit 24cafde231
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 111 additions and 46 deletions

View file

@ -125,6 +125,40 @@ impl fmt::Display for RawValue {
}
}
impl ToHex for RawValue {
fn encode_hex<T: std::iter::FromIterator<char>>(&self) -> T {
self.0
.iter()
.rev()
.fold(String::with_capacity(64), |mut s, limb| {
write!(s, "{:016x}", limb.0).unwrap();
s
})
.chars()
.collect()
}
fn encode_hex_upper<T: std::iter::FromIterator<char>>(&self) -> T {
self.0
.iter()
.rev()
.fold(String::with_capacity(64), |mut s, limb| {
write!(s, "{:016X}", limb.0).unwrap();
s
})
.chars()
.collect()
}
}
impl FromHex for RawValue {
type Error = FromHexError;
fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error> {
Hash::from_hex(hex).map(|h| RawValue(h.0))
}
}
#[derive(Clone, Copy, Debug, Default, Hash, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct Hash(
#[serde(