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

Commit 1c90f86

Browse files
authored
chore: implement Display instead of ToString (#828)
* Implement `Display` instead of `ToString` From the [standard library documentation](https://doc.rust-lang.org/std/string/trait.ToString.html): > This trait is automatically implemented for any type which implements the `Display` trait. As such, `ToString` shouldn't be implemented directly: `Display` should be implemented instead, and you get the `ToString` implementation for free. * Fix `fmt` import
1 parent 34855cf commit 1c90f86

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/definitions/block_context.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{state::BlockInfo, utils::Address};
22
use cairo_vm::felt::Felt252;
3+
use core::fmt;
34
use getset::{CopyGetters, Getters, MutGetters};
45
use starknet_api::block::Block;
56
use std::collections::HashMap;
@@ -17,14 +18,13 @@ pub enum StarknetChainId {
1718
TestNet2,
1819
}
1920

20-
impl ToString for StarknetChainId {
21-
fn to_string(&self) -> String {
21+
impl fmt::Display for StarknetChainId {
22+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2223
match self {
23-
StarknetChainId::MainNet => "SN_MAIN",
24-
StarknetChainId::TestNet => "SN_GOERLI",
25-
StarknetChainId::TestNet2 => "SN_GOERLI2",
24+
StarknetChainId::MainNet => write!(f, "SN_MAIN"),
25+
StarknetChainId::TestNet => write!(f, "SN_GOERLI"),
26+
StarknetChainId::TestNet2 => write!(f, "SN_GOERLI2"),
2627
}
27-
.to_string()
2828
}
2929
}
3030

0 commit comments

Comments
 (0)