Skip to content

Commit

Permalink
fix: accept signed
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Nov 15, 2023
1 parent 6293cc9 commit bd022b9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,21 @@ impl<'de> serde::Deserialize<'de> for Chain {
formatter.write_str("chain name or ID")
}

fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
if v.is_negative() {
Err(serde::de::Error::invalid_value(serde::de::Unexpected::Signed(v), &self))
} else {
Ok(Chain::from_id(v as u64))
}
}

fn visit_u64<E: serde::de::Error>(self, value: u64) -> Result<Self::Value, E> {
Ok(Chain::from_id(value))
}

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

fn visit_string<E: serde::de::Error>(self, v: String) -> Result<Self::Value, E> {
self.visit_str(&v)
}
}

deserializer.deserialize_any(ChainVisitor)
Expand Down

0 comments on commit bd022b9

Please sign in to comment.