Skip to content

Commit

Permalink
cargo clippy --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Apr 16, 2024
1 parent c08aeb0 commit 1e38ad5
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions packages/cosmos/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,47 @@ impl HasAddressHrp for CosmosNetwork {
}
}

impl serde::Serialize for Address {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&self.to_string())
}
}

impl<'de> serde::Deserialize<'de> for Address {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
deserializer.deserialize_str(AddressVisitor)
}
}

struct AddressVisitor;

impl<'de> Visitor<'de> for AddressVisitor {
type Value = Address;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("Cosmos address")
}

fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
v.parse().map_err(|e| E::custom(e))
}
}

impl Debug for Address {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "\"{self}\"")
}
}

#[cfg(test)]
mod tests {
use quickcheck::Arbitrary;
Expand Down Expand Up @@ -492,44 +533,3 @@ mod tests {
AddressHrp::new("juno with space").unwrap_err();
}
}

impl serde::Serialize for Address {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&self.to_string())
}
}

impl<'de> serde::Deserialize<'de> for Address {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
deserializer.deserialize_str(AddressVisitor)
}
}

struct AddressVisitor;

impl<'de> Visitor<'de> for AddressVisitor {
type Value = Address;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("Cosmos address")
}

fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
v.parse().map_err(|e| E::custom(e))
}
}

impl Debug for Address {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "\"{self}\"")
}
}

0 comments on commit 1e38ad5

Please sign in to comment.