Skip to content

Commit

Permalink
Merge rust-bitcoin/rust-bitcoin#905: Disable Serde's default-features
Browse files Browse the repository at this point in the history
76fcf81 Override default visit_byte_buf on Script (ass3rt)
add100c Removed reimplementations of default methods (ass3rt)
7db03f2 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 76fcf81
  tcharding:
    ACK 76fcf81
  apoelstra:
    ACK 76fcf81

Tree-SHA512: 5748e64e1f91f19dbfbf32bead6e6d759e448e92ed0dab731b3059f6b37bd811fad6654edc8fbd113e3be17fefaf9fc4912145d6b61484ced0517712361ecfdc
  • Loading branch information
apoelstra committed Apr 30, 2022
2 parents aef788b + 2a927d4 commit 8966ec7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -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]
Expand Down
21 changes: 7 additions & 14 deletions src/blockdata/script.rs
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
42 changes: 0 additions & 42 deletions src/internal_macros.rs
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8966ec7

Please sign in to comment.