Skip to content

Commit 22c4487

Browse files
authored
Bump rust + fix some clippy (#140)
1 parent adf1251 commit 22c4487

File tree

17 files changed

+56
-70
lines changed

17 files changed

+56
-70
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111

1212
env:
1313
CARGO_TERM_COLOR: always
14-
rust_stable: 1.64.0
14+
rust_stable: 1.68.2
1515

1616
jobs:
1717
build:

examples/activity_interaction.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@ async fn requestor_start(
4545

4646
async fn requestor_stop(client: &ActivityRequestorControlApi, activity_id: &str) -> Result<()> {
4747
println!("[-] Activity {}", activity_id);
48-
client.destroy_activity(&activity_id).await?;
48+
client.destroy_activity(activity_id).await?;
4949
println!("[<] Destroyed");
5050
Ok(())
5151
}
5252

5353
async fn requestor_exec(client: &ActivityRequestorControlApi, activity_id: &str) -> Result<()> {
5454
let exe_request = ExeScriptRequest::new("STOP".to_string());
5555
println!("[+] Batch exe script:{:?}", exe_request);
56-
let batch_id = client.exec(exe_request, &activity_id).await?;
56+
let batch_id = client.exec(exe_request, activity_id).await?;
5757
println!("[<] Batch id: {}", batch_id);
5858

5959
println!("[?] Batch results for activity {}", activity_id);
6060
let results = client
61-
.get_exec_batch_results(&activity_id, &batch_id, Some(10.), None)
61+
.get_exec_batch_results(activity_id, &batch_id, Some(10.), None)
6262
.await?;
6363
println!("[<] Batch results: {:?}", results);
6464
Ok(())

examples/market_interaction.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use serde_json;
21
use std::{env, thread, time::Duration};
32
use structopt::StructOpt;
43
use url::Url;
@@ -197,7 +196,7 @@ async fn requestor_interact(options: Options, nanos: u32) -> Result<()> {
197196
while requestor_events.is_empty() {
198197
demand_id = round_robin_demands();
199198
println!("REQUESTOR=> | waiting for events: {}", demand_id);
200-
requestor_events = client.collect(&demand_id, Some(1.0), Some(2)).await?;
199+
requestor_events = client.collect(demand_id, Some(1.0), Some(2)).await?;
201200
}
202201
println!("REQUESTOR=> | Yay! Got event(s): {:#?}", requestor_events);
203202

@@ -208,7 +207,7 @@ async fn requestor_interact(options: Options, nanos: u32) -> Result<()> {
208207
let proposal_id = &proposal.proposal_id;
209208

210209
// this is not needed in regular flow; just to illustrate possibility
211-
let offer_proposal = client.get_proposal(&demand_id, proposal_id).await?;
210+
let offer_proposal = client.get_proposal(demand_id, proposal_id).await?;
212211
cmp_proposals(&offer_proposal, &proposal);
213212

214213
match proposal.state {
@@ -219,7 +218,7 @@ async fn requestor_interact(options: Options, nanos: u32) -> Result<()> {
219218
println!("REQUESTOR=> | Negotiating proposal...");
220219
let bespoke_proposal = demand.clone();
221220
let new_proposal_id = client
222-
.counter_proposal(&bespoke_proposal, &demand_id, proposal_id)
221+
.counter_proposal(&bespoke_proposal, demand_id, proposal_id)
223222
.await?;
224223
println!(
225224
"REQUESTOR=> | Responded with counter proposal(id: {})",

model/src/activity/activity_state.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl ActivityState {
3131
impl From<&StatePair> for ActivityState {
3232
fn from(pending: &StatePair) -> Self {
3333
ActivityState {
34-
state: pending.clone(),
34+
state: *pending,
3535
reason: None,
3636
error_message: None,
3737
}
@@ -48,20 +48,21 @@ impl From<StatePair> for ActivityState {
4848
}
4949
}
5050

51-
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
51+
#[derive(
52+
Clone, Copy, Default, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize,
53+
)]
5254
pub struct StatePair(pub State, pub Option<State>);
5355

5456
impl StatePair {
5557
pub fn alive(&self) -> bool {
56-
match (&self.0, &self.1) {
57-
(State::Terminated, _) => false,
58-
(_, Some(State::Terminated)) => false,
59-
_ => true,
60-
}
58+
!matches!(
59+
(&self.0, &self.1),
60+
(State::Terminated, _) | (_, Some(State::Terminated))
61+
)
6162
}
6263

6364
pub fn to_pending(&self, state: State) -> Self {
64-
StatePair(self.0.clone(), Some(state))
65+
StatePair(self.0, Some(state))
6566
}
6667
}
6768

@@ -71,24 +72,15 @@ impl From<State> for StatePair {
7172
}
7273
}
7374

74-
impl Default for StatePair {
75-
fn default() -> Self {
76-
StatePair(State::default(), None)
77-
}
78-
}
79-
80-
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
75+
#[derive(
76+
Clone, Default, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize,
77+
)]
8178
pub enum State {
79+
#[default]
8280
New,
8381
Initialized,
8482
Deployed,
8583
Ready,
8684
Terminated,
8785
Unresponsive,
8886
}
89-
90-
impl Default for State {
91-
fn default() -> Self {
92-
State::New
93-
}
94-
}

model/src/activity/encrypted.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl EncryptionCtx {
9393
self.aeskey.as_ref(),
9494
Some(iv.as_ref()),
9595
&[],
96-
buf.as_ref(),
96+
buf,
9797
tag.as_mut(),
9898
)
9999
.map_err(EncryptionError::encrypt_err_msg)?;

model/src/activity/exe_script_command.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,16 @@ pub enum CaptureMode {
8282
},
8383
}
8484

85-
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
85+
#[derive(Clone, Default, Debug, PartialEq, Eq, Serialize, Deserialize)]
8686
#[serde(rename_all = "lowercase")]
8787
pub enum CaptureFormat {
88+
#[default]
8889
#[serde(alias = "string")]
8990
Str,
9091
#[serde(alias = "binary")]
9192
Bin,
9293
}
9394

94-
impl Default for CaptureFormat {
95-
fn default() -> Self {
96-
CaptureFormat::Str
97-
}
98-
}
99-
10095
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
10196
#[serde(rename_all = "camelCase")]
10297
pub enum CapturePart {

model/src/activity/sgx_credentials.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ mod binenc {
6464
where
6565
S: Serializer,
6666
{
67-
let s = hex::encode(&bytes);
67+
let s = hex::encode(bytes);
6868
serializer.serialize_str(&s)
6969
}
7070

@@ -73,7 +73,7 @@ mod binenc {
7373
D: Deserializer<'de>,
7474
{
7575
let s = String::deserialize(deserializer)?;
76-
let bytes = hex::decode(&s).map_err(D::Error::custom)?;
76+
let bytes = hex::decode(s).map_err(D::Error::custom)?;
7777
Ok(bytes)
7878
}
7979
}

model/src/node_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ impl NodeId {
4242
{
4343
let mut hex_str = [0u8; 42];
4444

45-
hex_str[0] = '0' as u8;
46-
hex_str[1] = 'x' as u8;
45+
hex_str[0] = b'0';
46+
hex_str[1] = b'x';
4747

4848
let mut ptr = 2;
4949
for it in &self.inner {

model/src/payment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub mod invoice_event;
1212
pub mod market_decoration;
1313
pub mod network;
1414
pub mod params;
15+
#[allow(clippy::module_inception)]
1516
pub mod payment;
1617
pub mod rejection;
1718
pub mod rejection_reason;

model/src/payment/debit_note_event.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ mod test {
4545
event_type: DebitNoteEventType::DebitNoteRejectedEvent {
4646
rejection: Rejection {
4747
rejection_reason: RejectionReason::UnsolicitedService,
48-
total_amount_accepted: BigDecimal::from_f32(3.14).unwrap(),
48+
total_amount_accepted: BigDecimal::from_f32(13.14).unwrap(),
4949
message: None,
5050
},
5151
},
@@ -57,7 +57,7 @@ mod test {
5757
\"eventType\":\"DebitNoteRejectedEvent\",\
5858
\"rejection\":{\
5959
\"rejectionReason\":\"UNSOLICITED_SERVICE\",\
60-
\"totalAmountAccepted\":\"3.140000\"\
60+
\"totalAmountAccepted\":\"13.14000\"\
6161
}\
6262
}",
6363
serde_json::to_string(&ie).unwrap()

model/src/payment/invoice_event.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ mod test {
4545
event_type: InvoiceEventType::InvoiceRejectedEvent {
4646
rejection: Rejection {
4747
rejection_reason: RejectionReason::UnsolicitedService,
48-
total_amount_accepted: BigDecimal::from_f32(3.14).unwrap(),
48+
total_amount_accepted: BigDecimal::from_f32(13.14).unwrap(),
4949
message: None,
5050
},
5151
},
@@ -57,7 +57,7 @@ mod test {
5757
\"eventType\":\"InvoiceRejectedEvent\",\
5858
\"rejection\":{\
5959
\"rejectionReason\":\"UNSOLICITED_SERVICE\",\
60-
\"totalAmountAccepted\":\"3.140000\"\
60+
\"totalAmountAccepted\":\"13.14000\"\
6161
}\
6262
}",
6363
serde_json::to_string(&ie).unwrap()

model/src/payment/params.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ where
8787
D: Deserializer<'de>,
8888
{
8989
let s: &str = Deserialize::deserialize(deserializer)?;
90-
Ok(s.split(",").map(str::to_string).collect())
90+
Ok(s.split(',').map(str::to_string).collect())
9191
}

model/src/payment/rejection_reason.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
use serde::{Deserialize, Serialize};
22

3-
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
3+
#[derive(
4+
Clone, Default, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize,
5+
)]
46
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
57
pub enum RejectionReason {
8+
#[default]
69
UnsolicitedService,
710
BadService,
811
IncorrectAmount,
912
}
10-
11-
impl Default for RejectionReason {
12-
fn default() -> Self {
13-
RejectionReason::UnsolicitedService
14-
}
15-
}

src/activity/provider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl WebInterface for ActivityProviderApi {
2323
impl ActivityProviderApi {
2424
/// Fetch list of activity_ids
2525
pub async fn get_activity_ids(&self) -> Result<Vec<String>> {
26-
self.client.get(&"activity").send().json().await
26+
self.client.get("activity").send().json().await
2727
}
2828

2929
/// Fetch activity state (which may include error details)

src/activity/requestor/control.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl ActivityRequestorControlApi {
5252
let s = secp256k1::Secp256k1::new();
5353
let (secret, pub_key) = s.generate_keypair(&mut rand::thread_rng());
5454
let result = self
55-
.create_secure_activity_raw(agreement_id, pub_key.clone())
55+
.create_secure_activity_raw(agreement_id, pub_key)
5656
.await?;
5757
let api = sgx::SecureActivityRequestorApi::from_response(
5858
self.client.clone(),
@@ -209,7 +209,7 @@ pub mod sgx {
209209
None => return Err(SgxError::MissingKeys),
210210
Some(_) => return Err(SgxError::InvalidKeys),
211211
};
212-
let enclave_key = sgx.enclave_pub_key.clone();
212+
let enclave_key = sgx.enclave_pub_key;
213213
let ctx = EncryptionCtx::new(&enclave_key, &requestor_key);
214214
let nonce = &activity_id.to_owned();
215215
let session = Arc::new(Session {
@@ -294,7 +294,7 @@ pub mod sgx {
294294
enc::Response::Error(e) => Err(e),
295295
_ => return Err(AppError::InternalError("invalid response".to_string())),
296296
};
297-
Ok(resp.map_err(|e| AppError::InternalError(e.to_string()))?)
297+
resp.map_err(|e| AppError::InternalError(e.to_string()))
298298
}
299299

300300
pub async fn get_exec_batch_results(
@@ -314,7 +314,7 @@ pub mod sgx {
314314
enc::Response::Error(e) => Err(e),
315315
_ => return Err(AppError::InternalError("invalid response".to_string())),
316316
};
317-
Ok(resp.map_err(|e| AppError::InternalError(e.to_string()))?)
317+
resp.map_err(|e| AppError::InternalError(e.to_string()))
318318
}
319319

320320
pub async fn get_running_command(
@@ -332,7 +332,7 @@ pub mod sgx {
332332
enc::Response::Error(e) => Err(e),
333333
_ => return Err(AppError::InternalError("invalid response".to_string())),
334334
};
335-
Ok(resp.map_err(|e| AppError::InternalError(e.to_string()))?)
335+
resp.map_err(|e| AppError::InternalError(e.to_string()))
336336
}
337337

338338
async fn send(&self, request: enc::Request) -> Result<enc::Response> {

src/net.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl NetVpnApi {
123123

124124
let status = res.status();
125125
if status.is_success().not() && status.is_informational().not() {
126-
let body = res.body().limit(16384 as usize).await?;
126+
let body = res.body().limit(16384).await?;
127127
return Err(Error::HttpError {
128128
code: status,
129129
msg: String::from_utf8(body.to_vec())?,

0 commit comments

Comments
 (0)