Skip to content

Commit ee6be44

Browse files
authored
fix(rust): use new format macros (#728)
2 parents 5ab03e4 + 87d5554 commit ee6be44

9 files changed

Lines changed: 38 additions & 35 deletions

.github/workflows/test-rust-examples.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@ jobs:
1414
working-directory: ./examples/developer-hub-rust
1515
steps:
1616
- uses: actions/checkout@v4
17-
- name: Install dependencies
18-
run: cargo build
17+
18+
- name: Install Rust toolchain
19+
uses: dtolnay/rust-toolchain@stable
20+
with:
21+
components: rustfmt, clippy
22+
23+
- name: Cache dependencies
24+
uses: Swatinem/rust-cache@v2
25+
1926
- name: Format with rustfmt
2027
run: cargo fmt -- --check
28+
2129
- name: Lint with clippy
2230
run: cargo clippy -- -D warnings
31+
2332
- name: Run tests
2433
run: ./test.sh

examples/developer-hub-rust/src/bin/chain_id_coston2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ async fn main() -> Result<()> {
66
let provider =
77
ProviderBuilder::new().on_http("https://coston2-api.flare.network/ext/C/rpc".parse()?);
88
let chain_id = provider.get_chain_id().await?;
9-
println!("Chain ID: {}", chain_id); // Chain ID: 114
9+
println!("Chain ID: {chain_id}"); // Chain ID: 114
1010
Ok(())
1111
}

examples/developer-hub-rust/src/bin/chain_id_flare.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ async fn main() -> Result<()> {
66
let provider =
77
ProviderBuilder::new().on_http("https://flare-api.flare.network/ext/C/rpc".parse()?);
88
let chain_id = provider.get_chain_id().await?;
9-
println!("Chain ID: {}", chain_id); // Chain ID: 14
9+
println!("Chain ID: {chain_id}"); // Chain ID: 14
1010
Ok(())
1111
}

examples/developer-hub-rust/src/bin/fetch_anchor_feeds.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub async fn fetch_anchor_feed(
2222

2323
let mut url = format!("{BASE_URL}api/v0/ftso/anchor-feeds-with-proof");
2424
if let Some(id) = voting_round_id {
25-
url.push_str(&format!("?voting_round_id={}", id));
25+
url.push_str(&format!("?voting_round_id={id}"));
2626
}
2727

2828
let response = client
@@ -40,7 +40,7 @@ pub async fn fetch_anchor_feed(
4040
#[tokio::main]
4141
async fn main() {
4242
match fetch_anchor_feed(FEED_IDS, None).await {
43-
Ok(data) => println!("Anchor feeds data: {:?}", data),
44-
Err(err) => eprintln!("Error fetching anchor feeds: {}", err),
43+
Ok(data) => println!("Anchor feeds data: {data:?}"),
44+
Err(err) => eprintln!("Error fetching anchor feeds: {err}"),
4545
}
4646
}

examples/developer-hub-rust/src/bin/fetch_and_verify_anchor_onchain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ mod convert_type {
9595
// Convert hex to bytes using the hex crate
9696
let mut bytes = [0u8; 32];
9797
hex::decode_to_slice(clean_hex, &mut bytes)
98-
.map_err(|e| format!("Hex decoding failed: {}", e))?;
98+
.map_err(|e| format!("Hex decoding failed: {e}"))?;
9999

100100
Ok(FixedBytes::<32>::from(bytes))
101101
}
@@ -154,7 +154,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
154154
.watch()
155155
.await?;
156156

157-
println!("Save Price transaction hash: {}", tx_hash);
157+
println!("Save Price transaction hash: {tx_hash}");
158158

159159
let feed_id: FixedBytes<21> = {
160160
let hex_str = BTC_USD_FEED_ID

examples/developer-hub-rust/src/bin/ftsov2_consumer_coston2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ async fn main() -> Result<()> {
2626
// Fetch current feeds
2727
let FtsoV2::getFeedsByIdReturn { _0, _1, _2 } = ftsov2.getFeedsById(feed_ids).call().await?;
2828
// Print results
29-
println!("Feeds:{:?} ", _0);
30-
println!("Decimals:{:?} ", _1);
31-
println!("Timestamp:{:?} ", _2);
29+
println!("Feeds:{_0:?}");
30+
println!("Decimals:{_1:?}");
31+
println!("Timestamp:{_2:?}");
3232
Ok(())
3333
}

examples/developer-hub-rust/src/bin/get_feed_id.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ fn get_feed_id(category: &str, feed_name: &str) -> String {
22
let hex_feed_name = feed_name
33
.as_bytes()
44
.iter()
5-
.map(|byte| format!("{:02x}", byte))
5+
.map(|byte| format!("{byte:02x}"))
66
.collect::<Vec<String>>()
77
.join("");
8-
let combined = format!("{}{}", category, hex_feed_name);
9-
let padded_hex_string = format!("{:0<42}", combined);
10-
format!("0x{}", padded_hex_string)
8+
let combined = format!("{category}{hex_feed_name}");
9+
let padded_hex_string = format!("{combined:0<42}");
10+
format!("0x{padded_hex_string}")
1111
}
1212

1313
fn main() {
1414
let feed_id = get_feed_id("01", "FLR/USD");
15-
println!("{}", feed_id);
15+
println!("{feed_id}");
1616
}

examples/developer-hub-rust/src/bin/secure_random_coston2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ async fn main() -> Result<()> {
2525
_randomTimestamp,
2626
} = random_v2.getRandomNumber().call().await?;
2727
// Print results
28-
println!("Random Number: {:?} ", _randomNumber);
29-
println!("Is secure random: {:?} ", _isSecureRandom);
30-
println!("Timestamp: {:?} ", _randomTimestamp);
28+
println!("Random Number: {_randomNumber:?}");
29+
println!("Is secure random: {_isSecureRandom:?}");
30+
println!("Timestamp: {_randomTimestamp:?}");
3131
Ok(())
3232
}

examples/developer-hub-rust/src/bin/volatility_incentive_coston2.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,10 @@ async fn main() -> Result<()> {
3939
incentive.getRange().call().await?;
4040
let FastUpdatesIncentiveManager::getScaleReturn { _0: scale } =
4141
incentive.getScale().call().await?;
42-
println!(
43-
"Sample Size Increase Price: {:?} ",
44-
sample_size_increase_price
45-
);
46-
println!("Current Sample Size: {:?} ", expected_sample_size);
47-
println!("Current Range: {:?} ", range);
48-
println!("Current Scale: {:?} ", scale);
42+
println!("Sample Size Increase Price: {sample_size_increase_price:?}");
43+
println!("Current Sample Size: {expected_sample_size:?}");
44+
println!("Current Range: {range:?}");
45+
println!("Current Scale: {scale:?}");
4946

5047
// Offer the incentive
5148
let offer = FastUpdatesIncentiveManager::IncentiveOffer {
@@ -59,7 +56,7 @@ async fn main() -> Result<()> {
5956
.await?
6057
.watch()
6158
.await?;
62-
println!("Offer Incentive Tx Hash: {:?}", tx_hash);
59+
println!("Offer Incentive Tx Hash: {tx_hash:?}");
6360

6461
// Get the new sample size increase price, sample size, range, and scale
6562
let FastUpdatesIncentiveManager::getCurrentSampleSizeIncreasePriceReturn {
@@ -72,12 +69,9 @@ async fn main() -> Result<()> {
7269
incentive.getRange().call().await?;
7370
let FastUpdatesIncentiveManager::getScaleReturn { _0: scale } =
7471
incentive.getScale().call().await?;
75-
println!(
76-
"Sample Size Increase Price: {:?} ",
77-
sample_size_increase_price
78-
);
79-
println!("Current Sample Size: {:?} ", exp_sample_size);
80-
println!("Current Range: {:?} ", range);
81-
println!("Current Scale: {:?} ", scale);
72+
println!("Sample Size Increase Price: {sample_size_increase_price:?} ");
73+
println!("Current Sample Size: {exp_sample_size:?}");
74+
println!("Current Range: {range:?}");
75+
println!("Current Scale: {scale:?}");
8276
Ok(())
8377
}

0 commit comments

Comments
 (0)