Skip to content

Commit 2c08d74

Browse files
committed
clippy
1 parent 0c844c2 commit 2c08d74

File tree

14 files changed

+52
-69
lines changed

14 files changed

+52
-69
lines changed

examples/distributed_bakery.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async fn increment(State(state): State<Arc<AppState>>) -> Result<Json<u32>, ()>
3232

3333
// Increment the output
3434
if let Ok(output) = increment_output(&state.doc_handle).await {
35-
println!("Incremented output to {:?}.", output);
35+
println!("Incremented output to {output:?}.");
3636

3737
// Exit the critical section.
3838
start_outside_the_bakery(&state.doc_handle, &state.customer_id).await;
@@ -236,10 +236,10 @@ async fn request_increment(
236236
loop {
237237
sleep(Duration::from_millis(1000)).await;
238238
for addr in http_addrs.iter() {
239-
let url = format!("http://{}/increment", addr);
239+
let url = format!("http://{addr}/increment");
240240
if let Ok(new) = client.get(url).send().await {
241241
if let Ok(new) = new.json().await {
242-
println!("Got new increment: {:?}, versus old one: {:?}", new, last);
242+
println!("Got new increment: {new:?}, versus old one: {last:?}");
243243
assert!(new > last);
244244
last = new;
245245
}
@@ -331,17 +331,17 @@ async fn main() {
331331
let http_addrs: Vec<String> = customers
332332
.iter()
333333
.filter(|id| id != &&args.customer_id)
334-
.map(|id| format!("0.0.0.0:300{}", id))
334+
.map(|id| format!("0.0.0.0:300{id}"))
335335
.collect();
336336
let tcp_addrs: Vec<String> = customers
337337
.iter()
338338
.filter(|id| id != &&args.customer_id)
339-
.map(|id| format!("127.0.0.1:234{}", id))
339+
.map(|id| format!("127.0.0.1:234{id}"))
340340
.collect();
341341

342342
// Our addrs
343-
let our_http_addr = format!("0.0.0.0:300{}", customer_id);
344-
let our_tcp_addr = format!("127.0.0.1:234{}", customer_id);
343+
let our_http_addr = format!("0.0.0.0:300{customer_id}");
344+
let our_tcp_addr = format!("127.0.0.1:234{customer_id}");
345345

346346
// Create a repo.
347347
let repo = Repo::new(None, Box::new(NoStorage));
@@ -359,7 +359,7 @@ async fn main() {
359359
.await
360360
.unwrap();
361361
}
362-
Err(e) => println!("couldn't get client: {:?}", e),
362+
Err(e) => println!("couldn't get client: {e:?}"),
363363
}
364364
}
365365
});
@@ -412,7 +412,7 @@ async fn main() {
412412
let client = reqwest::Client::new();
413413
let mut doc_id = None;
414414
for addr in http_addrs.iter() {
415-
let url = format!("http://{}/get_doc_id", addr);
415+
let url = format!("http://{addr}/get_doc_id");
416416
let res = client.get(url).send().await;
417417
if res.is_err() {
418418
continue;

examples/tcp-example.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async fn new_doc(State(state): State<Arc<AppState>>) -> Json<DocumentId> {
4747
let our_id = state.repo_handle.get_repo_id();
4848
doc_handle.with_doc_mut(|doc| {
4949
let mut tx = doc.transaction();
50-
tx.put(automerge::ROOT, "repo_id", format!("{}", our_id))
50+
tx.put(automerge::ROOT, "repo_id", format!("{our_id}"))
5151
.expect("Failed to change the document.");
5252
tx.commit();
5353
});
@@ -194,7 +194,7 @@ async fn main() {
194194
.await
195195
.unwrap();
196196
}
197-
Err(e) => println!("couldn't get client: {:?}", e),
197+
Err(e) => println!("couldn't get client: {e:?}"),
198198
}
199199
}
200200
});
@@ -231,7 +231,7 @@ async fn main() {
231231
.expect("Failed to read the document.")
232232
.unwrap();
233233
let val = val.0.to_str().unwrap();
234-
println!("Synced: {:?} to {:?}", doc_id, val);
234+
println!("Synced: {doc_id:?} to {val:?}");
235235
});
236236
}
237237
Handle::current()

src/conn_complete.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ impl std::fmt::Display for ConnFinishedReason {
3232
ConnFinishedReason::RepoShutdown => write!(f, "Repository shutdown"),
3333
ConnFinishedReason::DuplicateConnection => write!(f, "Duplicate connection"),
3434
ConnFinishedReason::TheyDisconnected => write!(f, "They disconnected"),
35-
ConnFinishedReason::ErrorReceiving(msg) => write!(f, "Error receiving: {}", msg),
36-
ConnFinishedReason::ErrorSending(msg) => write!(f, "Error sending: {}", msg),
35+
ConnFinishedReason::ErrorReceiving(msg) => write!(f, "Error receiving: {msg}"),
36+
ConnFinishedReason::ErrorSending(msg) => write!(f, "Error sending: {msg}"),
3737
}
3838
}
3939
}

src/fs_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ impl SavedChunkName {
393393
fn filename(&self) -> String {
394394
let hash = hex::encode(&self.hash);
395395
match self.chunk_type {
396-
ChunkType::Incremental => format!("{}.incremental", hash),
397-
ChunkType::Snapshot => format!("{}.snapshot", hash),
396+
ChunkType::Incremental => format!("{hash}.incremental"),
397+
ChunkType::Snapshot => format!("{hash}.snapshot"),
398398
}
399399
}
400400
}

src/interfaces.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl TryFrom<Vec<u8>> for DocumentId {
5252
fn try_from(v: Vec<u8>) -> Result<Self, Self::Error> {
5353
match uuid::Uuid::from_slice(v.as_slice()) {
5454
Ok(id) => Ok(Self(id.into_bytes())),
55-
Err(e) => Err(BadDocumentId(format!("invalid uuid: {}", e))),
55+
Err(e) => Err(BadDocumentId(format!("invalid uuid: {e}"))),
5656
}
5757
}
5858
}
@@ -79,14 +79,14 @@ impl FromStr for DocumentId {
7979
impl std::fmt::Debug for DocumentId {
8080
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8181
let as_string = bs58::encode(&self.0).with_check().into_string();
82-
write!(f, "{}", as_string)
82+
write!(f, "{as_string}")
8383
}
8484
}
8585

8686
impl Display for DocumentId {
8787
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
8888
let as_string = bs58::encode(&self.0).with_check().into_string();
89-
write!(f, "{}", as_string)
89+
write!(f, "{as_string}")
9090
}
9191
}
9292

@@ -99,7 +99,7 @@ pub enum NetworkError {
9999
impl Display for NetworkError {
100100
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
101101
match self {
102-
NetworkError::Error(e) => write!(f, "NetworkError: {}", e),
102+
NetworkError::Error(e) => write!(f, "NetworkError: {e}"),
103103
}
104104
}
105105
}
@@ -132,8 +132,7 @@ impl std::fmt::Debug for RepoMessage {
132132
message: _,
133133
} => write!(
134134
f,
135-
"Sync {{ from_repo_id: {:?}, to_repo_id: {:?}, document_id: {:?} }}",
136-
from_repo_id, to_repo_id, document_id
135+
"Sync {{ from_repo_id: {from_repo_id:?}, to_repo_id: {to_repo_id:?}, document_id: {document_id:?} }}"
137136
),
138137
RepoMessage::Ephemeral {
139138
from_repo_id,
@@ -142,8 +141,7 @@ impl std::fmt::Debug for RepoMessage {
142141
message: _,
143142
} => write!(
144143
f,
145-
"Ephemeral {{ from_repo_id: {:?}, to_repo_id: {:?}, document_id: {:?} }}",
146-
from_repo_id, to_repo_id, document_id
144+
"Ephemeral {{ from_repo_id: {from_repo_id:?}, to_repo_id: {to_repo_id:?}, document_id: {document_id:?} }}"
147145
),
148146
}
149147
}

src/network_connect.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ impl RepoHandle {
4141
Err(e) => {
4242
tracing::error!(?e, repo_id=?repo_id, "Error receiving repo message");
4343
Err(NetworkError::Error(format!(
44-
"error receiving repo message: {}",
45-
e
44+
"error receiving repo message: {e}"
4645
)))
4746
}
4847
}
@@ -55,7 +54,7 @@ impl RepoHandle {
5554
})
5655
.sink_map_err(|e| {
5756
tracing::error!(?e, "Error sending repo message");
58-
NetworkError::Error(format!("error sending repo message: {}", e))
57+
NetworkError::Error(format!("error sending repo message: {e}"))
5958
});
6059

6160
Ok(self.new_remote_repo(other_id, Box::new(stream), Box::new(sink)))
@@ -80,18 +79,15 @@ impl RepoHandle {
8079
Ok(Message::Join(other_id)) => other_id,
8180
Ok(other) => {
8281
return Err(NetworkError::Error(format!(
83-
"unexpected message (expecting join): {:?}",
84-
other
82+
"unexpected message (expecting join): {other:?}"
8583
)))
8684
}
87-
Err(e) => {
88-
return Err(NetworkError::Error(format!("error reciving: {}", e)))
89-
}
85+
Err(e) => return Err(NetworkError::Error(format!("error reciving: {e}"))),
9086
};
9187
let msg = Message::Peer(self.get_repo_id().clone());
9288
sink.send(msg)
9389
.await
94-
.map_err(|e| NetworkError::Error(format!("error sending: {}", e)))?;
90+
.map_err(|e| NetworkError::Error(format!("error sending: {e}")))?;
9591
Ok(other_id)
9692
} else {
9793
Err(NetworkError::Error(
@@ -103,15 +99,14 @@ impl RepoHandle {
10399
let msg = Message::Join(self.get_repo_id().clone());
104100
sink.send(msg)
105101
.await
106-
.map_err(|e| NetworkError::Error(format!("send error: {}", e)))?;
102+
.map_err(|e| NetworkError::Error(format!("send error: {e}")))?;
107103
let msg = stream.next().await;
108104
match msg {
109105
Some(Ok(Message::Peer(sender))) => Ok(sender),
110106
Some(Ok(other)) => Err(NetworkError::Error(format!(
111-
"unexpected message (expecting peer): {:?}",
112-
other
107+
"unexpected message (expecting peer): {other:?}"
113108
))),
114-
Some(Err(e)) => Err(NetworkError::Error(format!("error sending: {}", e))),
109+
Some(Err(e)) => Err(NetworkError::Error(format!("error sending: {e}"))),
115110
None => Err(NetworkError::Error(
116111
"unexpected end of receive stream".to_string(),
117112
)),

src/repo.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,7 @@ impl DocumentInfo {
821821
if let Err(e) = res {
822822
self.state
823823
.resolve_load_fut(Err(RepoError::Incorrect(format!(
824-
"error loading document: {:?}",
825-
e
824+
"error loading document: {e:?}"
826825
))));
827826
self.state = DocState::Error;
828827
return None;
@@ -878,8 +877,7 @@ impl DocumentInfo {
878877
if let Err(e) = res {
879878
self.state
880879
.resolve_bootstrap_fut(Err(RepoError::Incorrect(format!(
881-
"error loading document: {:?}",
882-
e
880+
"error loading document: {e:?}"
883881
))));
884882
self.state = DocState::Error;
885883
return None;
@@ -1342,8 +1340,7 @@ impl Repo {
13421340
}
13431341
Err(e) => {
13441342
tracing::error!(error = ?e, "Error decoding sync message.");
1345-
let msg =
1346-
format!("error decoding received sync message: {}", e);
1343+
let msg = format!("error decoding received sync message: {e}");
13471344
break Some(ConnFinishedReason::ErrorReceiving(msg));
13481345
}
13491346
},

src/tokio/websocket.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,8 @@ impl RepoHandle {
111111
use futures::TryStreamExt;
112112

113113
let stream = stream
114-
.map_err(|e| NetworkError::Error(format!("error receiving websocket message: {}", e)))
115-
.sink_map_err(|e| {
116-
NetworkError::Error(format!("error sending websocket message: {}", e))
117-
});
114+
.map_err(|e| NetworkError::Error(format!("error receiving websocket message: {e}")))
115+
.sink_map_err(|e| NetworkError::Error(format!("error sending websocket message: {e}")));
118116
self.connect_tokio_websocket(stream, direction).await
119117
}
120118

@@ -175,10 +173,8 @@ impl RepoHandle {
175173
use futures::TryStreamExt;
176174

177175
let stream = stream
178-
.map_err(|e| NetworkError::Error(format!("error receiving websocket message: {}", e)))
179-
.sink_map_err(|e| {
180-
NetworkError::Error(format!("error sending websocket message: {}", e))
181-
});
176+
.map_err(|e| NetworkError::Error(format!("error receiving websocket message: {e}")))
177+
.sink_map_err(|e| NetworkError::Error(format!("error sending websocket message: {e}")));
182178
self.connect_tokio_websocket(stream, ConnDirection::Incoming)
183179
.await
184180
}
@@ -219,15 +215,14 @@ impl RepoHandle {
219215
Ok(m) => m,
220216
Err(e) => {
221217
return Some(Err(NetworkError::Error(format!(
222-
"websocket receive error: {}",
223-
e
218+
"websocket receive error: {e}"
224219
))));
225220
}
226221
};
227222
match msg.into() {
228223
WsMessage::Binary(data) => Some(Message::decode(&data).map_err(|e| {
229224
tracing::error!(err=?e, msg=%hex::encode(data), "error decoding message");
230-
NetworkError::Error(format!("error decoding message: {}", e))
225+
NetworkError::Error(format!("error decoding message: {e}"))
231226
})),
232227
WsMessage::Close => {
233228
tracing::debug!("websocket closing");
@@ -248,7 +243,7 @@ impl RepoHandle {
248243
}).boxed();
249244

250245
let msg_sink = PollSender::new(tx.clone())
251-
.sink_map_err(|e| NetworkError::Error(format!("websocket send error: {}", e)))
246+
.sink_map_err(|e| NetworkError::Error(format!("websocket send error: {e}")))
252247
.with(|msg: Message| {
253248
futures::future::ready(Ok::<_, NetworkError>(WsMessage::Binary(msg.encode())))
254249
});
@@ -260,7 +255,7 @@ impl RepoHandle {
260255
while let Some(msg) = rx.recv().await {
261256
if let Err(e) = sink.send(msg.into()).await {
262257
tracing::error!(err=?e, "error sending message");
263-
return Err(NetworkError::Error(format!("error sending message: {}", e)));
258+
return Err(NetworkError::Error(format!("error sending message: {e}")));
264259
}
265260
}
266261
Ok(())
@@ -276,7 +271,7 @@ impl RepoHandle {
276271
match res {
277272
Err(e) => {
278273
tracing::error!(err=?e, "error sending message");
279-
return Err(NetworkError::Error(format!("error sending message: {}", e)));
274+
return Err(NetworkError::Error(format!("error sending message: {e}")));
280275
}
281276
Ok(()) => {
282277
tracing::error!("websocket send loop unexpectedly stopped");

tests/interop/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn sync_two_repos(port: u16) {
3030
let storage1 = Box::<InMemoryStorage>::default();
3131
let repo1 = Repo::new(None, storage1);
3232
let repo1_handle = repo1.run();
33-
let (conn, _) = tokio_tungstenite::connect_async(format!("ws://localhost:{}", port))
33+
let (conn, _) = tokio_tungstenite::connect_async(format!("ws://localhost:{port}"))
3434
.await
3535
.unwrap();
3636

@@ -59,7 +59,7 @@ fn sync_two_repos(port: u16) {
5959
let repo2 = Repo::new(None, storage2);
6060
let repo2_handle = repo2.run();
6161

62-
let (conn2, _) = tokio_tungstenite::connect_async(format!("ws://localhost:{}", port))
62+
let (conn2, _) = tokio_tungstenite::connect_async(format!("ws://localhost:{port}"))
6363
.await
6464
.unwrap();
6565
let conn2_driver = repo2_handle
@@ -116,7 +116,7 @@ fn start_js_server() -> Child {
116116

117117
// Wait for the server to start up
118118
loop {
119-
match reqwest::blocking::get(format!("http://localhost:{}/", PORT)) {
119+
match reqwest::blocking::get(format!("http://localhost:{PORT}/")) {
120120
Ok(r) => {
121121
if r.status().is_success() {
122122
break;
@@ -125,7 +125,7 @@ fn start_js_server() -> Child {
125125
}
126126
}
127127
Err(e) => {
128-
println!("Error connecting to server: {}", e);
128+
println!("Error connecting to server: {e}");
129129
}
130130
}
131131
sleep(Duration::from_millis(100));

tests/network/conn_complete.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ async fn conn_complete_future_resolves_on_duplicate_connection() {
7070
(ConnFinishedReason::DuplicateConnection, ConnFinishedReason::TheyDisconnected) => {}
7171
(ConnFinishedReason::TheyDisconnected, ConnFinishedReason::DuplicateConnection) => {}
7272
(ConnFinishedReason::DuplicateConnection, ConnFinishedReason::DuplicateConnection) => {}
73-
(left, right) => panic!("Unexpected result, left: {:?}, right: {:?}", left, right),
73+
(left, right) => panic!("Unexpected result, left: {left:?}, right: {right:?}"),
7474
}
7575
}

0 commit comments

Comments
 (0)