From 1dfe6d0cd2f799981181bb6a95d04333e945e500 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 4 Jun 2022 20:37:37 +0200 Subject: [PATCH] feat: add display impl for BlockNumber (#1346) --- ethers-core/src/types/block.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ethers-core/src/types/block.rs b/ethers-core/src/types/block.rs index 75beac62..c516318c 100644 --- a/ethers-core/src/types/block.rs +++ b/ethers-core/src/types/block.rs @@ -9,7 +9,7 @@ use serde::{ ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer, }; -use std::{fmt::Formatter, str::FromStr}; +use std::{fmt, fmt::Formatter, str::FromStr}; use thiserror::Error; /// The block type returned from RPC calls. @@ -579,6 +579,17 @@ impl FromStr for BlockNumber { } } +impl fmt::Display for BlockNumber { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + BlockNumber::Number(ref x) => format!("0x{:x}", x).fmt(f), + BlockNumber::Latest => f.write_str("latest"), + BlockNumber::Earliest => f.write_str("earliest"), + BlockNumber::Pending => f.write_str("pending"), + } + } +} + #[cfg(test)] #[cfg(not(feature = "celo"))] mod tests {