Merge rust-bitcoin/rust-bitcoin#905: Disable Serde's default-features

76fcf81474 Override default visit_byte_buf on Script (ass3rt)
add100c20d Removed reimplementations of default methods (ass3rt)
7db03f27e4 Disable Serde's default-features (ass3rt)

Pull request description:

  With this patch, existing users of the `use-serde` feature will no longer be
  compiling with `serde/std` enabled, but this allows dependent projects
  to import serde and enable `serde/alloc` as required by some no-std targets.

ACKs for top commit:
  Kixunil:
    ACK 76fcf81474
  tcharding:
    ACK 76fcf81474
  apoelstra:
    ACK 76fcf81474

Tree-SHA512: 5748e64e1f91f19dbfbf32bead6e6d759e448e92ed0dab731b3059f6b37bd811fad6654edc8fbd113e3be17fefaf9fc4912145d6b61484ced0517712361ecfdc
This commit is contained in:
Andrew Poelstra 2022-04-30 15:51:09 +00:00
commit 9f817982a3
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
3 changed files with 8 additions and 57 deletions

View File

@ -41,7 +41,7 @@ core2 = { version = "0.3.0", optional = true, default-features = false }
base64-compat = { version = "1.0.0", optional = true }
bitcoinconsensus = { version = "0.19.0-3", optional = true }
serde = { version = "1", features = [ "derive" ], optional = true }
serde = { version = "1", default-features = false, features = [ "derive", "alloc" ], optional = true }
hashbrown = { version = "0.8", optional = true }
[dev-dependencies]

View File

@ -1024,20 +1024,6 @@ impl<'de> serde::Deserialize<'de> for Script {
let v = Vec::from_hex(v).map_err(E::custom)?;
Ok(Script::from(v))
}
fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
self.visit_str(v)
}
fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
self.visit_str(&v)
}
}
deserializer.deserialize_str(Visitor)
} else {
@ -1056,6 +1042,13 @@ impl<'de> serde::Deserialize<'de> for Script {
{
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)
}

View File

@ -152,20 +152,6 @@ macro_rules! serde_string_impl {
{
$name::from_str(v).map_err(E::custom)
}
fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>
where
E: $crate::serde::de::Error,
{
self.visit_str(v)
}
fn visit_string<E>(self, v: $crate::prelude::String) -> Result<Self::Value, E>
where
E: $crate::serde::de::Error,
{
self.visit_str(&v)
}
}
deserializer.deserialize_str(Visitor)
@ -215,19 +201,6 @@ macro_rules! serde_struct_human_string_impl {
$name::from_str(v).map_err(E::custom)
}
fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>
where
E: $crate::serde::de::Error,
{
self.visit_str(v)
}
fn visit_string<E>(self, v: $crate::prelude::String) -> Result<Self::Value, E>
where
E: $crate::serde::de::Error,
{
self.visit_str(&v)
}
}
deserializer.deserialize_str(Visitor)
@ -573,21 +546,6 @@ macro_rules! user_enum {
Err(E::unknown_variant(v, FIELDS))
}
}
fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>
where
E: $crate::serde::de::Error,
{
self.visit_str(v)
}
fn visit_string<E>(self, v: $crate::prelude::String) -> Result<Self::Value, E>
where
E: $crate::serde::de::Error,
{
self.visit_str(&v)
}
}
deserializer.deserialize_str(Visitor)