Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit 1dfe6d0

Browse files
authored
feat: add display impl for BlockNumber (#1346)
1 parent 00b38c4 commit 1dfe6d0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Diff for: ethers-core/src/types/block.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use serde::{
99
ser::SerializeStruct,
1010
Deserialize, Deserializer, Serialize, Serializer,
1111
};
12-
use std::{fmt::Formatter, str::FromStr};
12+
use std::{fmt, fmt::Formatter, str::FromStr};
1313
use thiserror::Error;
1414

1515
/// The block type returned from RPC calls.
@@ -579,6 +579,17 @@ impl FromStr for BlockNumber {
579579
}
580580
}
581581

582+
impl fmt::Display for BlockNumber {
583+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
584+
match self {
585+
BlockNumber::Number(ref x) => format!("0x{:x}", x).fmt(f),
586+
BlockNumber::Latest => f.write_str("latest"),
587+
BlockNumber::Earliest => f.write_str("earliest"),
588+
BlockNumber::Pending => f.write_str("pending"),
589+
}
590+
}
591+
}
592+
582593
#[cfg(test)]
583594
#[cfg(not(feature = "celo"))]
584595
mod tests {

0 commit comments

Comments
 (0)