Skip to content

Commit d179fd2

Browse files
committed
Remove unnecessary clone
1 parent 07571e9 commit d179fd2

File tree

6 files changed

+58
-63
lines changed

6 files changed

+58
-63
lines changed

src/agent/market_schedule.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const MAX_TIME_INSTANT: NaiveTime = NaiveTime::MIN
4747
.overflowing_sub_signed(Duration::nanoseconds(1))
4848
.0;
4949

50-
#[derive(Clone, Debug, Eq, PartialEq)]
50+
#[derive(Debug, Eq, PartialEq, Clone)]
5151
pub struct MarketSchedule {
5252
pub timezone: Tz,
5353
pub weekly_schedule: Vec<ScheduleDayKind>,
@@ -193,8 +193,9 @@ impl Display for HolidayDaySchedule {
193193
}
194194
}
195195

196-
#[derive(Clone, Debug, Eq, PartialEq)]
196+
#[derive(Default, Clone, Debug, Eq, PartialEq)]
197197
pub enum ScheduleDayKind {
198+
#[default]
198199
Open,
199200
Closed,
200201
TimeRanges(Vec<RangeInclusive<NaiveTime>>),
@@ -210,12 +211,6 @@ impl ScheduleDayKind {
210211
}
211212
}
212213

213-
impl Default for ScheduleDayKind {
214-
fn default() -> Self {
215-
Self::Open
216-
}
217-
}
218-
219214
impl Display for ScheduleDayKind {
220215
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
221216
match self {

src/agent/pyth.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use {
44
Serialize,
55
},
66
std::collections::BTreeMap,
7+
std::sync::Arc,
78
};
89

910
pub mod rpc;
@@ -16,28 +17,28 @@ pub type Exponent = i64;
1617
pub type Conf = u64;
1718
pub type Slot = u64;
1819

19-
#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)]
20+
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)]
2021
pub struct ProductAccountMetadata {
2122
pub account: Pubkey,
2223
pub attr_dict: Attrs,
23-
pub price: Vec<PriceAccountMetadata>,
24+
pub price: Arc<[PriceAccountMetadata]>,
2425
}
2526

26-
#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)]
27+
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)]
2728
pub struct PriceAccountMetadata {
2829
pub account: Pubkey,
2930
pub price_type: String,
3031
pub price_exponent: Exponent,
3132
}
3233

33-
#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)]
34+
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)]
3435
pub struct ProductAccount {
3536
pub account: Pubkey,
3637
pub attr_dict: Attrs,
37-
pub price_accounts: Vec<PriceAccount>,
38+
pub price_accounts: Arc<[PriceAccount]>,
3839
}
3940

40-
#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)]
41+
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)]
4142
pub struct PriceAccount {
4243
pub account: Pubkey,
4344
pub price_type: String,
@@ -52,10 +53,10 @@ pub struct PriceAccount {
5253
pub prev_slot: Slot,
5354
pub prev_price: Price,
5455
pub prev_conf: Conf,
55-
pub publisher_accounts: Vec<PublisherAccount>,
56+
pub publisher_accounts: Arc<[PublisherAccount]>,
5657
}
5758

58-
#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)]
59+
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)]
5960
pub struct PublisherAccount {
6061
pub account: Pubkey,
6162
pub status: String,
@@ -64,20 +65,20 @@ pub struct PublisherAccount {
6465
pub slot: Slot,
6566
}
6667

67-
#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)]
68+
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)]
6869
pub struct NotifyPrice {
6970
pub subscription: SubscriptionID,
7071
pub result: PriceUpdate,
7172
}
7273

73-
#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)]
74+
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)]
7475
pub struct NotifyPriceSched {
7576
pub subscription: SubscriptionID,
7677
}
7778

7879
pub type SubscriptionID = i64;
7980

80-
#[derive(Serialize, Deserialize, Debug, Clone, Ord, PartialOrd, PartialEq, Eq)]
81+
#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, PartialEq, Eq)]
8182
pub struct PriceUpdate {
8283
pub price: Price,
8384
pub conf: Conf,

src/agent/state.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ mod tests {
247247
]
248248
.map(|(k, v)| (k.to_string(), v.to_string())),
249249
),
250-
price_accounts: vec![
250+
price_accounts: [
251251
solana_sdk::pubkey::Pubkey::from_str(
252252
"GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU",
253253
)
@@ -260,7 +260,7 @@ mod tests {
260260
"2V7t5NaKY7aGkwytCWQgvUYZfEr9XMwNChhJEakTExk6",
261261
)
262262
.unwrap(),
263-
],
263+
].into(),
264264
},
265265
),
266266
(
@@ -280,7 +280,7 @@ mod tests {
280280
]
281281
.map(|(k, v)| (k.to_string(), v.to_string())),
282282
),
283-
price_accounts: vec![
283+
price_accounts: [
284284
solana_sdk::pubkey::Pubkey::from_str(
285285
"GG3FTE7xhc9Diy7dn9P6BWzoCrAEE4D3p5NBYrDAm5DD",
286286
)
@@ -293,7 +293,7 @@ mod tests {
293293
"GKNcUmNacSJo4S2Kq3DuYRYRGw3sNUfJ4tyqd198t6vQ",
294294
)
295295
.unwrap(),
296-
],
296+
].into(),
297297
},
298298
),
299299
]),
@@ -372,7 +372,7 @@ mod tests {
372372
]
373373
.map(|(k, v)| (k.to_string(), v.to_string())),
374374
),
375-
price: vec![
375+
price: [
376376
PriceAccountMetadata {
377377
account: "GG3FTE7xhc9Diy7dn9P6BWzoCrAEE4D3p5NBYrDAm5DD".to_string(),
378378
price_type: "price".to_string(),
@@ -388,7 +388,7 @@ mod tests {
388388
price_type: "price".to_string(),
389389
price_exponent: 2,
390390
},
391-
],
391+
].into(),
392392
},
393393
ProductAccountMetadata {
394394
account: "CkMrDWtmFJZcmAUC11qNaWymbXQKvnRx4cq1QudLav7t".to_string(),
@@ -403,7 +403,7 @@ mod tests {
403403
]
404404
.map(|(k, v)| (k.to_string(), v.to_string())),
405405
),
406-
price: vec![
406+
price: [
407407
PriceAccountMetadata {
408408
account: "GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU".to_string(),
409409
price_type: "price".to_string(),
@@ -419,7 +419,7 @@ mod tests {
419419
price_type: "price".to_string(),
420420
price_exponent: -6,
421421
},
422-
],
422+
].into(),
423423
},
424424
];
425425

@@ -482,7 +482,7 @@ mod tests {
482482
},
483483
schedule: Default::default(),
484484
publish_interval: None,
485-
price_accounts: vec![
485+
price_accounts: [
486486
solana_sdk::pubkey::Pubkey::from_str(
487487
"GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU",
488488
)
@@ -495,7 +495,7 @@ mod tests {
495495
"2V7t5NaKY7aGkwytCWQgvUYZfEr9XMwNChhJEakTExk6",
496496
)
497497
.unwrap(),
498-
],
498+
].into(),
499499
}
500500
.into(),
501501
),
@@ -544,7 +544,7 @@ mod tests {
544544
},
545545
schedule: Default::default(),
546546
publish_interval: None,
547-
price_accounts: vec![
547+
price_accounts: [
548548
solana_sdk::pubkey::Pubkey::from_str(
549549
"GG3FTE7xhc9Diy7dn9P6BWzoCrAEE4D3p5NBYrDAm5DD",
550550
)
@@ -557,7 +557,7 @@ mod tests {
557557
"GKNcUmNacSJo4S2Kq3DuYRYRGw3sNUfJ4tyqd198t6vQ",
558558
)
559559
.unwrap(),
560-
],
560+
].into(),
561561
}
562562
.into(),
563563
),
@@ -1075,7 +1075,7 @@ mod tests {
10751075
]
10761076
.map(|(k, v)| (k.to_string(), v.to_string())),
10771077
),
1078-
price_accounts: vec![
1078+
price_accounts: [
10791079
pyth::PriceAccount {
10801080
account: "GG3FTE7xhc9Diy7dn9P6BWzoCrAEE4D3p5NBYrDAm5DD"
10811081
.to_string(),
@@ -1091,7 +1091,7 @@ mod tests {
10911091
prev_slot: 791279274,
10921092
prev_price: 98272648,
10931093
prev_conf: 124986284,
1094-
publisher_accounts: vec![
1094+
publisher_accounts: [
10951095
PublisherAccount {
10961096
account: "F42dQ3SMssashRsA4SRfwJxFkGKV1bE3TcmpkagX8vvX".to_string(),
10971097
status: "trading".to_string(),
@@ -1106,7 +1106,7 @@ mod tests {
11061106
conf: 55896,
11071107
slot: 32976,
11081108
},
1109-
],
1109+
].into(),
11101110
},
11111111
pyth::PriceAccount {
11121112
account: "fTNjSfj5uW9e4CAMHzUcm65ftRNBxCN1gG5GS1mYfid"
@@ -1123,7 +1123,7 @@ mod tests {
11231123
prev_slot: 893734828,
11241124
prev_price: 13947294,
11251125
prev_conf: 349274938,
1126-
publisher_accounts: vec![
1126+
publisher_accounts: [
11271127
PublisherAccount {
11281128
account: "8MMroLyuyxyeDRrzMNfpymC5RvmHtQiYooXX9bgeUJdM".to_string(),
11291129
status: "unknown".to_string(),
@@ -1138,7 +1138,7 @@ mod tests {
11381138
conf: 8962196,
11391139
slot: 301541,
11401140
},
1141-
],
1141+
].into(),
11421142
},
11431143
pyth::PriceAccount {
11441144
account: "GKNcUmNacSJo4S2Kq3DuYRYRGw3sNUfJ4tyqd198t6vQ"
@@ -1155,15 +1155,15 @@ mod tests {
11551155
prev_slot: 8878456286,
11561156
prev_price: 24746384,
11571157
prev_conf: 6373957,
1158-
publisher_accounts: vec![PublisherAccount {
1158+
publisher_accounts: [PublisherAccount {
11591159
account: "33B2brfdz16kizEXeQvYzJXHiS1X95L8pfetuyntEiXg".to_string(),
11601160
status: "trading".to_string(),
11611161
price: 61478,
11621162
conf: 312545,
11631163
slot: 302156,
1164-
}],
1164+
}].into(),
11651165
},
1166-
],
1166+
].into(),
11671167
},
11681168
pyth::ProductAccount {
11691169
account: "CkMrDWtmFJZcmAUC11qNaWymbXQKvnRx4cq1QudLav7t".to_string(),
@@ -1178,7 +1178,7 @@ mod tests {
11781178
]
11791179
.map(|(k, v)| (k.to_string(), v.to_string())),
11801180
),
1181-
price_accounts: vec![
1181+
price_accounts: [
11821182
pyth::PriceAccount {
11831183
account: "GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU"
11841184
.to_string(),
@@ -1194,7 +1194,7 @@ mod tests {
11941194
prev_slot: 172761778,
11951195
prev_price: 22691000,
11961196
prev_conf: 398674,
1197-
publisher_accounts: vec![],
1197+
publisher_accounts: [].into(),
11981198
},
11991199
pyth::PriceAccount {
12001200
account: "3VQwtcntVQN1mj1MybQw8qK7Li3KNrrgNskSQwZAPGNr"
@@ -1211,13 +1211,13 @@ mod tests {
12111211
prev_slot: 1727612348,
12121212
prev_price: 746383678,
12131213
prev_conf: 757368,
1214-
publisher_accounts: vec![PublisherAccount {
1214+
publisher_accounts: [PublisherAccount {
12151215
account: "C9syZ2MoGUwbPyGEgiy8MxesaEEKLdJw8gnwx2jLK1cV".to_string(),
12161216
status: "trading".to_string(),
12171217
price: 85698,
12181218
conf: 23645,
12191219
slot: 14765,
1220-
}],
1220+
}].into(),
12211221
},
12221222
pyth::PriceAccount {
12231223
account: "2V7t5NaKY7aGkwytCWQgvUYZfEr9XMwNChhJEakTExk6"
@@ -1234,7 +1234,7 @@ mod tests {
12341234
prev_slot: 86484638,
12351235
prev_price: 28463947,
12361236
prev_conf: 83628234,
1237-
publisher_accounts: vec![
1237+
publisher_accounts: [
12381238
PublisherAccount {
12391239
account: "DaMuPaW5dhGfRJaX7TzLWXd8hDCMJ5WA2XibJ12hjBNQ".to_string(),
12401240
status: "trading".to_string(),
@@ -1249,9 +1249,9 @@ mod tests {
12491249
conf: 7456,
12501250
slot: 865,
12511251
},
1252-
],
1252+
].into(),
12531253
},
1254-
],
1254+
].into(),
12551255
},
12561256
];
12571257

@@ -1280,7 +1280,7 @@ mod tests {
12801280
// Check that the result of the conversion to the Pythd API format is what we expected
12811281
let expected = ProductAccount {
12821282
account: account.to_string(),
1283-
price_accounts: vec![
1283+
price_accounts: [
12841284
pyth::PriceAccount {
12851285
account: "GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU".to_string(),
12861286
price_type: "price".to_string(),
@@ -1295,7 +1295,7 @@ mod tests {
12951295
prev_slot: 172761778,
12961296
prev_price: 22691000,
12971297
prev_conf: 398674,
1298-
publisher_accounts: vec![],
1298+
publisher_accounts: [].into(),
12991299
},
13001300
pyth::PriceAccount {
13011301
account: "3VQwtcntVQN1mj1MybQw8qK7Li3KNrrgNskSQwZAPGNr".to_string(),
@@ -1311,13 +1311,13 @@ mod tests {
13111311
prev_slot: 1727612348,
13121312
prev_price: 746383678,
13131313
prev_conf: 757368,
1314-
publisher_accounts: vec![PublisherAccount {
1314+
publisher_accounts: [PublisherAccount {
13151315
account: "C9syZ2MoGUwbPyGEgiy8MxesaEEKLdJw8gnwx2jLK1cV".to_string(),
13161316
status: "trading".to_string(),
13171317
price: 85698,
13181318
conf: 23645,
13191319
slot: 14765,
1320-
}],
1320+
}].into(),
13211321
},
13221322
pyth::PriceAccount {
13231323
account: "2V7t5NaKY7aGkwytCWQgvUYZfEr9XMwNChhJEakTExk6".to_string(),
@@ -1333,7 +1333,7 @@ mod tests {
13331333
prev_slot: 86484638,
13341334
prev_price: 28463947,
13351335
prev_conf: 83628234,
1336-
publisher_accounts: vec![
1336+
publisher_accounts: [
13371337
PublisherAccount {
13381338
account: "DaMuPaW5dhGfRJaX7TzLWXd8hDCMJ5WA2XibJ12hjBNQ".to_string(),
13391339
status: "trading".to_string(),
@@ -1348,9 +1348,9 @@ mod tests {
13481348
conf: 7456,
13491349
slot: 865,
13501350
},
1351-
],
1351+
].into(),
13521352
},
1353-
],
1353+
].into(),
13541354
attr_dict: BTreeMap::from(
13551355
[
13561356
("symbol", "Crypto.LTC/USD"),

0 commit comments

Comments
 (0)