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:
parent
335100d1d7
commit
24cafde231
10 changed files with 111 additions and 46 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue