Skip to content

Commit 78a20d1

Browse files
committed
refactor(ilp-cli): clippy simpler enum_variant_names suggestion
Signed-off-by: Ömer Talha Özdemir <omertoast@gmail.com>
1 parent bfab5ac commit 78a20d1

File tree

4 files changed

+46
-54
lines changed

4 files changed

+46
-54
lines changed

crates/ilp-cli/src/interpreter.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ use url::Url;
1212
pub enum Error {
1313
// Custom errors
1414
#[error("Usage error")]
15-
UsageErr(&'static str),
15+
Usage(&'static str),
1616
#[error("Invalid protocol in URL: {0}")]
17-
ProtocolErr(String),
17+
Protocol(String),
1818
// Foreign errors
1919
#[error("Error sending HTTP request: {0}")]
20-
SendErr(#[from] reqwest::Error),
20+
Send(#[from] reqwest::Error),
2121
#[error("Error receving HTTP response from testnet: {0}")]
22-
TestnetErr(reqwest::Error),
22+
Testnet(reqwest::Error),
2323
#[error("Error altering URL scheme")]
24-
SchemeErr(()), // TODO: should be part of UrlError, see https://github.com/servo/rust-url/issues/299
24+
Scheme(()), // TODO: should be part of Urlor, see https://github.com/servo/rust-url/issues/299
2525
#[error("Error parsing URL: {0}")]
26-
UrlErr(#[from] url::ParseError),
26+
Url(#[from] url::ParseError),
2727
#[error("WebSocket error: {0}")]
28-
WebsocketErr(#[from] tungstenite::error::Error),
28+
Websocket(#[from] tungstenite::error::Error),
2929
#[error("HTTP error: {0}")]
30-
HttpErr(#[from] http::Error),
30+
Http(#[from] http::Error),
3131
}
3232

3333
pub fn run(matches: &ArgMatches) -> Result<Response, Error> {
@@ -49,35 +49,35 @@ pub fn run(matches: &ArgMatches) -> Result<Response, Error> {
4949
("list", Some(submatches)) => client.get_accounts(submatches),
5050
("update", Some(submatches)) => client.put_account(submatches),
5151
("update-settings", Some(submatches)) => client.put_account_settings(submatches),
52-
_ => Err(Error::UsageErr("ilp-cli help accounts")),
52+
_ => Err(Error::Usage("ilp-cli help accounts")),
5353
},
5454
("pay", Some(pay_matches)) => client.post_account_payments(pay_matches),
5555
("rates", Some(rates_matches)) => match rates_matches.subcommand() {
5656
("list", Some(submatches)) => client.get_rates(submatches),
5757
("set-all", Some(submatches)) => client.put_rates(submatches),
58-
_ => Err(Error::UsageErr("ilp-cli help rates")),
58+
_ => Err(Error::Usage("ilp-cli help rates")),
5959
},
6060
("routes", Some(routes_matches)) => match routes_matches.subcommand() {
6161
("list", Some(submatches)) => client.get_routes(submatches),
6262
("set", Some(submatches)) => client.put_route_static(submatches),
6363
("set-all", Some(submatches)) => client.put_routes_static(submatches),
64-
_ => Err(Error::UsageErr("ilp-cli help routes")),
64+
_ => Err(Error::Usage("ilp-cli help routes")),
6565
},
6666
("settlement-engines", Some(settlement_matches)) => match settlement_matches.subcommand() {
6767
("set-all", Some(submatches)) => client.put_settlement_engines(submatches),
68-
_ => Err(Error::UsageErr("ilp-cli help settlement-engines")),
68+
_ => Err(Error::Usage("ilp-cli help settlement-engines")),
6969
},
7070
("status", Some(status_matches)) => client.get_root(status_matches),
7171
("logs", Some(log_level)) => client.put_tracing_level(log_level),
7272
("testnet", Some(testnet_matches)) => match testnet_matches.subcommand() {
7373
("setup", Some(submatches)) => client.xpring_account(submatches),
74-
_ => Err(Error::UsageErr("ilp-cli help testnet")),
74+
_ => Err(Error::Usage("ilp-cli help testnet")),
7575
},
7676
("payments", Some(payments_matches)) => match payments_matches.subcommand() {
7777
("incoming", Some(submatches)) => client.ws_payments_incoming(submatches),
78-
_ => Err(Error::UsageErr("ilp-cli help payments")),
78+
_ => Err(Error::Usage("ilp-cli help payments")),
7979
},
80-
_ => Err(Error::UsageErr("ilp-cli help")),
80+
_ => Err(Error::Usage("ilp-cli help")),
8181
}
8282
}
8383

@@ -95,7 +95,7 @@ impl NodeClient<'_> {
9595
.get(&format!("{}/accounts/{}/balance", self.url, user))
9696
.bearer_auth(auth)
9797
.send()
98-
.map_err(Error::SendErr)
98+
.map_err(Error::Send)
9999
}
100100

101101
// POST /accounts
@@ -106,7 +106,7 @@ impl NodeClient<'_> {
106106
.bearer_auth(auth)
107107
.json(&args)
108108
.send()
109-
.map_err(Error::SendErr)
109+
.map_err(Error::Send)
110110
}
111111

112112
// PUT /accounts/:username
@@ -117,7 +117,7 @@ impl NodeClient<'_> {
117117
.bearer_auth(auth)
118118
.json(&args)
119119
.send()
120-
.map_err(Error::SendErr)
120+
.map_err(Error::Send)
121121
}
122122

123123
// DELETE /accounts/:username
@@ -127,7 +127,7 @@ impl NodeClient<'_> {
127127
.delete(&format!("{}/accounts/{}", self.url, args["username"]))
128128
.bearer_auth(auth)
129129
.send()
130-
.map_err(Error::SendErr)
130+
.map_err(Error::Send)
131131
}
132132

133133
// WebSocket /accounts/:username/payments/incoming
@@ -141,13 +141,13 @@ impl NodeClient<'_> {
141141
let scheme = match url.scheme() {
142142
"http" => Ok("ws"),
143143
"https" => Ok("wss"),
144-
s => Err(Error::ProtocolErr(format!(
144+
s => Err(Error::Protocol(format!(
145145
"{} (only HTTP and HTTPS are supported)",
146146
s
147147
))),
148148
}?;
149149

150-
url.set_scheme(scheme).map_err(Error::SchemeErr)?;
150+
url.set_scheme(scheme).map_err(Error::Scheme)?;
151151

152152
let request: Request = Request::builder()
153153
.uri(url.into_string())
@@ -169,13 +169,13 @@ impl NodeClient<'_> {
169169
let scheme = match url.scheme() {
170170
"http" => Ok("ws"),
171171
"https" => Ok("wss"),
172-
s => Err(Error::ProtocolErr(format!(
172+
s => Err(Error::Protocol(format!(
173173
"{} (only HTTP and HTTPS are supported)",
174174
s
175175
))),
176176
}?;
177177

178-
url.set_scheme(scheme).map_err(Error::SchemeErr)?;
178+
url.set_scheme(scheme).map_err(Error::Scheme)?;
179179

180180
let request: Request = Request::builder()
181181
.uri(url.into_string())
@@ -196,7 +196,7 @@ impl NodeClient<'_> {
196196
.get(&format!("{}/accounts/{}", self.url, args["username"]))
197197
.bearer_auth(auth)
198198
.send()
199-
.map_err(Error::SendErr)
199+
.map_err(Error::Send)
200200
}
201201

202202
// GET /accounts
@@ -206,7 +206,7 @@ impl NodeClient<'_> {
206206
.get(&format!("{}/accounts", self.url))
207207
.bearer_auth(auth)
208208
.send()
209-
.map_err(Error::SendErr)
209+
.map_err(Error::Send)
210210
}
211211

212212
// PUT /accounts/:username/settings
@@ -218,7 +218,7 @@ impl NodeClient<'_> {
218218
.bearer_auth(auth)
219219
.json(&args)
220220
.send()
221-
.map_err(Error::SendErr)
221+
.map_err(Error::Send)
222222
}
223223

224224
// POST /accounts/:username/payments
@@ -230,15 +230,15 @@ impl NodeClient<'_> {
230230
.bearer_auth(auth)
231231
.json(&args)
232232
.send()
233-
.map_err(Error::SendErr)
233+
.map_err(Error::Send)
234234
}
235235

236236
// GET /rates
237237
fn get_rates(&self, _matches: &ArgMatches) -> Result<Response, Error> {
238238
self.client
239239
.get(&format!("{}/rates", self.url))
240240
.send()
241-
.map_err(Error::SendErr)
241+
.map_err(Error::Send)
242242
}
243243

244244
// PUT /rates
@@ -249,15 +249,15 @@ impl NodeClient<'_> {
249249
.bearer_auth(auth)
250250
.json(&rate_pairs)
251251
.send()
252-
.map_err(Error::SendErr)
252+
.map_err(Error::Send)
253253
}
254254

255255
// GET /routes
256256
fn get_routes(&self, _matches: &ArgMatches) -> Result<Response, Error> {
257257
self.client
258258
.get(&format!("{}/routes", self.url))
259259
.send()
260-
.map_err(Error::SendErr)
260+
.map_err(Error::Send)
261261
}
262262

263263
// PUT /routes/static/:prefix
@@ -268,7 +268,7 @@ impl NodeClient<'_> {
268268
.bearer_auth(auth)
269269
.body(args["destination"].to_string())
270270
.send()
271-
.map_err(Error::SendErr)
271+
.map_err(Error::Send)
272272
}
273273

274274
// PUT routes/static
@@ -279,7 +279,7 @@ impl NodeClient<'_> {
279279
.bearer_auth(auth)
280280
.json(&route_pairs)
281281
.send()
282-
.map_err(Error::SendErr)
282+
.map_err(Error::Send)
283283
}
284284

285285
// PUT /settlement/engines
@@ -290,7 +290,7 @@ impl NodeClient<'_> {
290290
.bearer_auth(auth)
291291
.json(&engine_pairs)
292292
.send()
293-
.map_err(Error::SendErr)
293+
.map_err(Error::Send)
294294
}
295295

296296
// PUT /tracing-level
@@ -301,15 +301,15 @@ impl NodeClient<'_> {
301301
.bearer_auth(auth)
302302
.body(args["level"].to_owned())
303303
.send()
304-
.map_err(Error::SendErr)
304+
.map_err(Error::Send)
305305
}
306306

307307
// GET /
308308
fn get_root(&self, _matches: &ArgMatches) -> Result<Response, Error> {
309309
self.client
310310
.get(&format!("{}/", self.url))
311311
.send()
312-
.map_err(Error::SendErr)
312+
.map_err(Error::Send)
313313
}
314314

315315
/*
@@ -332,7 +332,7 @@ impl NodeClient<'_> {
332332
.get(&format!("https://xpring.io/api/accounts/{}", asset))
333333
.send()?
334334
.json()
335-
.map_err(Error::TestnetErr)?;
335+
.map_err(Error::Testnet)?;
336336
let mut args = HashMap::new();
337337
let token = format!("{}:{}", foreign_args.username, foreign_args.passkey);
338338
args.insert("ilp_over_http_url", foreign_args.http_endpoint);
@@ -360,7 +360,7 @@ impl NodeClient<'_> {
360360
http::Response::builder().body(token).unwrap(), // infallible unwrap
361361
))
362362
} else {
363-
result.map_err(Error::SendErr)
363+
result.map_err(Error::Send)
364364
}
365365
}
366366
}

crates/ilp-cli/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn main() {
1414

1515
// 4. Handle interpreter output
1616
match result {
17-
Err(interpreter::Error::UsageErr(s)) => {
17+
Err(interpreter::Error::Usage(s)) => {
1818
// Clap doesn't seem to have a built-in way of manually printing the
1919
// help text for an arbitrary subcommand, but this works just the same.
2020
app.get_matches_from(s.split(' '));
@@ -217,9 +217,9 @@ mod interface_tests {
217217
Ok(matches) => match run(&matches) {
218218
// Because these are interface tests, not integration tests, network errors are expected
219219
Ok(_)
220-
| Err(Error::SendErr(_))
221-
| Err(Error::WebsocketErr(_))
222-
| Err(Error::TestnetErr(_)) => (),
220+
| Err(Error::Send(_))
221+
| Err(Error::Websocket(_))
222+
| Err(Error::Testnet(_)) => (),
223223
Err(e) => panic!("Unexpected interpreter failure: {}", e),
224224
},
225225
}

crates/interledger-service-util/src/echo_service.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,7 @@ mod echo_tests {
288288
assert_eq!(request.prepare.execution_condition(), execution_condition);
289289
assert_eq!(request.prepare.destination(), destination);
290290
assert_eq!(request.prepare.data(), &data[..]);
291-
Ok(FulfillBuilder {
292-
fulfillment,
293-
data,
294-
}
295-
.build())
291+
Ok(FulfillBuilder { fulfillment, data }.build())
296292
});
297293
let mut echo_service = EchoService::new(TestStore(node_address), handler);
298294

@@ -380,11 +376,7 @@ mod echo_tests {
380376
assert_eq!(request.prepare.execution_condition(), execution_condition);
381377
assert_eq!(request.prepare.destination(), source_address);
382378
assert_eq!(request.prepare.data(), &data[..]);
383-
Ok(FulfillBuilder {
384-
fulfillment,
385-
data,
386-
}
387-
.build())
379+
Ok(FulfillBuilder { fulfillment, data }.build())
388380
});
389381
let mut echo_service = EchoService::new(TestStore(node_address), handler);
390382

crates/interledger-stream/src/packet.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ impl<'a> FrameIterator<'a> {
288288
FrameType::ConnectionNewAddress => {
289289
Frame::ConnectionNewAddress(ConnectionNewAddressFrame::read_contents(contents)?)
290290
}
291-
FrameType::ConnectionAssetDetails => Frame::ConnectionAssetDetails(
292-
ConnectionAssetDetailsFrame::read_contents(contents)?,
293-
),
291+
FrameType::ConnectionAssetDetails => {
292+
Frame::ConnectionAssetDetails(ConnectionAssetDetailsFrame::read_contents(contents)?)
293+
}
294294
FrameType::ConnectionMaxData => {
295295
Frame::ConnectionMaxData(ConnectionMaxDataFrame::read_contents(contents)?)
296296
}

0 commit comments

Comments
 (0)