Skip to content

Commit ea93330

Browse files
fix: format code with cargo fmt
Co-Authored-By: Tejas Badadare <[email protected]>
1 parent f3bd3ad commit ea93330

25 files changed

+427
-201
lines changed

apps/hermes/client/rust/examples/latest_prices.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,21 @@ const ETH_PRICE_FEED_ID: &str = "ff61491a931112ddf1bd8147cd1b641375f79f5825126d6
1010
async fn main() -> Result<(), Box<dyn Error>> {
1111
let mut config = Configuration::new();
1212
config.base_path = "https://hermes.pyth.network".to_string();
13-
14-
let price_feed_ids = vec![
15-
BTC_PRICE_FEED_ID.to_string(),
16-
ETH_PRICE_FEED_ID.to_string()
17-
];
18-
13+
14+
let price_feed_ids = vec![BTC_PRICE_FEED_ID.to_string(), ETH_PRICE_FEED_ID.to_string()];
15+
1916
let price_update = rest_api::latest_price_updates(
20-
&config,
21-
price_feed_ids,
22-
Some(EncodingType::Base64),
17+
&config,
18+
price_feed_ids,
19+
Some(EncodingType::Base64),
2320
Some(true), // parsed
24-
Some(false) // ignore_invalid_price_ids
25-
).await?;
26-
21+
Some(false), // ignore_invalid_price_ids
22+
)
23+
.await?;
24+
2725
println!("Latest Price Updates:");
2826
println!("====================");
29-
27+
3028
if let Some(Some(parsed_updates)) = price_update.parsed {
3129
for update in parsed_updates {
3230
let price_feed_id = update.id;
@@ -35,22 +33,19 @@ async fn main() -> Result<(), Box<dyn Error>> {
3533
ETH_PRICE_FEED_ID => "ETH/USD",
3634
_ => "Unknown",
3735
};
38-
36+
3937
let price = &update.price;
4038
let price_value = price.price.parse::<f64>().unwrap_or(0.0) * 10f64.powi(price.expo);
4139
let conf_value = price.conf.parse::<f64>().unwrap_or(0.0) * 10f64.powi(price.expo);
42-
40+
4341
println!(
4442
"{}: ${:.2} (conf: ${:.2}, publish_time: {})",
45-
symbol,
46-
price_value,
47-
conf_value,
48-
price.publish_time
43+
symbol, price_value, conf_value, price.publish_time
4944
);
5045
}
5146
} else {
5247
println!("No parsed price data available");
5348
}
54-
49+
5550
Ok(())
5651
}
Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use futures_util::stream::StreamExt;
2-
use hermes_client::Configuration;
32
use hermes_client::create_price_update_stream;
3+
use hermes_client::Configuration;
44
use std::error::Error;
55

66
const BTC_PRICE_FEED_ID: &str = "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43";
@@ -10,25 +10,23 @@ const ETH_PRICE_FEED_ID: &str = "ff61491a931112ddf1bd8147cd1b641375f79f5825126d6
1010
async fn main() -> Result<(), Box<dyn Error>> {
1111
let mut config = Configuration::new();
1212
config.base_path = "https://hermes.pyth.network".to_string();
13-
14-
let price_feed_ids = vec![
15-
BTC_PRICE_FEED_ID.to_string(),
16-
ETH_PRICE_FEED_ID.to_string()
17-
];
18-
13+
14+
let price_feed_ids = vec![BTC_PRICE_FEED_ID.to_string(), ETH_PRICE_FEED_ID.to_string()];
15+
1916
println!("Starting SSE price stream for BTC/USD and ETH/USD...");
2017
println!("Press Ctrl+C to exit");
2118
println!("====================");
22-
19+
2320
let mut stream = create_price_update_stream(
2421
&config,
2522
price_feed_ids,
26-
None, // default encoding (base64)
27-
None, // default allow_unordered
28-
None, // default benchmarks_only
29-
None // default ignore_invalid_price_ids
30-
).await?;
31-
23+
None, // default encoding (base64)
24+
None, // default allow_unordered
25+
None, // default benchmarks_only
26+
None, // default ignore_invalid_price_ids
27+
)
28+
.await?;
29+
3230
while let Some(result) = stream.next().await {
3331
match result {
3432
Ok(update) => {
@@ -38,24 +36,22 @@ async fn main() -> Result<(), Box<dyn Error>> {
3836
ETH_PRICE_FEED_ID => "ETH/USD",
3937
_ => "Unknown",
4038
};
41-
39+
4240
let price = &update.price;
43-
let price_value = price.price.parse::<f64>().unwrap_or(0.0) * 10f64.powi(price.expo);
41+
let price_value =
42+
price.price.parse::<f64>().unwrap_or(0.0) * 10f64.powi(price.expo);
4443
let conf_value = price.conf.parse::<f64>().unwrap_or(0.0) * 10f64.powi(price.expo);
45-
44+
4645
println!(
4746
"{}: ${:.2} (conf: ${:.2}, publish_time: {})",
48-
symbol,
49-
price_value,
50-
conf_value,
51-
price.publish_time
47+
symbol, price_value, conf_value, price.publish_time
5248
);
53-
},
49+
}
5450
Err(e) => {
5551
eprintln!("Error: {}", e);
5652
}
5753
}
5854
}
59-
55+
6056
Ok(())
6157
}

apps/hermes/client/rust/src/apis/configuration.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
* Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle.
55
*
66
* The version of the OpenAPI document: 0.8.6
7-
*
7+
*
88
* Generated by: https://openapi-generator.tech
99
*/
1010

11-
12-
1311
#[derive(Debug, Clone)]
1412
pub struct Configuration {
1513
pub base_path: String,
@@ -29,7 +27,6 @@ pub struct ApiKey {
2927
pub key: String,
3028
}
3129

32-
3330
impl Configuration {
3431
pub fn new() -> Configuration {
3532
Configuration::default()

apps/hermes/client/rust/src/apis/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub enum Error<T> {
1616
ResponseError(ResponseContent<T>),
1717
}
1818

19-
impl <T> fmt::Display for Error<T> {
19+
impl<T> fmt::Display for Error<T> {
2020
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2121
let (module, e) = match self {
2222
Error::Reqwest(e) => ("reqwest", e.to_string()),
@@ -28,7 +28,7 @@ impl <T> fmt::Display for Error<T> {
2828
}
2929
}
3030

31-
impl <T: fmt::Debug> error::Error for Error<T> {
31+
impl<T: fmt::Debug> error::Error for Error<T> {
3232
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
3333
Some(match self {
3434
Error::Reqwest(e) => e,
@@ -39,19 +39,19 @@ impl <T: fmt::Debug> error::Error for Error<T> {
3939
}
4040
}
4141

42-
impl <T> From<reqwest::Error> for Error<T> {
42+
impl<T> From<reqwest::Error> for Error<T> {
4343
fn from(e: reqwest::Error) -> Self {
4444
Error::Reqwest(e)
4545
}
4646
}
4747

48-
impl <T> From<serde_json::Error> for Error<T> {
48+
impl<T> From<serde_json::Error> for Error<T> {
4949
fn from(e: serde_json::Error) -> Self {
5050
Error::Serde(e)
5151
}
5252
}
5353

54-
impl <T> From<std::io::Error> for Error<T> {
54+
impl<T> From<std::io::Error> for Error<T> {
5555
fn from(e: std::io::Error) -> Self {
5656
Error::Io(e)
5757
}
@@ -78,8 +78,10 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String
7878
value,
7979
));
8080
}
81-
},
82-
serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())),
81+
}
82+
serde_json::Value::String(s) => {
83+
params.push((format!("{}[{}]", prefix, key), s.clone()))
84+
}
8385
_ => params.push((format!("{}[{}]", prefix, key), value.to_string())),
8486
}
8587
}
@@ -96,7 +98,7 @@ pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String
9698
enum ContentType {
9799
Json,
98100
Text,
99-
Unsupported(String)
101+
Unsupported(String),
100102
}
101103

102104
impl From<&str> for ContentType {

0 commit comments

Comments
 (0)