Override default visit_byte_buf on Script

This override may avoid allocation and thus make the deserialization
faster.

Credit to Kixunil for this fix: https://github.com/rust-bitcoin/rust-bitcoin/pull/905#issuecomment-1092756343
This commit is contained in:
ass3rt 2022-04-25 09:48:36 -05:00
parent add100c20d
commit 76fcf81474
1 changed files with 7 additions and 0 deletions

View File

@ -1042,6 +1042,13 @@ impl<'de> serde::Deserialize<'de> for Script {
{ {
Ok(Script::from(v.to_vec())) Ok(Script::from(v.to_vec()))
} }
fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
Ok(Script::from(v))
}
} }
deserializer.deserialize_bytes(BytesVisitor) deserializer.deserialize_bytes(BytesVisitor)
} }