Skip to content

Commit a119756

Browse files
committed
Deal with some linter warnings
1 parent d1c7860 commit a119756

File tree

1 file changed

+31
-36
lines changed

1 file changed

+31
-36
lines changed

src/asgi/mod.rs

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -50,35 +50,30 @@ pub async fn execute_asgi_http_scope(
5050
let mut body = Vec::new();
5151
let mut response_started = false;
5252

53-
loop {
54-
if let Some(msg) = tx.recv().await {
55-
match msg {
56-
HttpSendMessage::HttpResponseStart {
57-
status: s,
58-
headers: h,
59-
trailers: _
60-
} => {
61-
status = s;
62-
headers = h;
63-
response_started = true;
64-
}
65-
HttpSendMessage::HttpResponseBody {
66-
body: b,
67-
more_body
68-
} => {
69-
if response_started {
70-
body.extend_from_slice(&b);
71-
if !more_body {
72-
// Response is complete
73-
let _ = response_tx.send((status, headers, body));
74-
break;
75-
}
53+
while let Some(msg) = tx.recv().await {
54+
match msg {
55+
HttpSendMessage::HttpResponseStart {
56+
status: s,
57+
headers: h,
58+
trailers: _
59+
} => {
60+
status = s;
61+
headers = h;
62+
response_started = true;
63+
}
64+
HttpSendMessage::HttpResponseBody {
65+
body: b,
66+
more_body
67+
} => {
68+
if response_started {
69+
body.extend_from_slice(&b);
70+
if !more_body {
71+
// Response is complete
72+
let _ = response_tx.send((status, headers, body));
73+
break;
7674
}
7775
}
7876
}
79-
} else {
80-
// Channel closed
81-
break;
8277
}
8378
}
8479
});
@@ -105,8 +100,8 @@ pub async fn execute_asgi_http_scope(
105100
let coroutine = match py_func.call1(py, (scope_py, rx_receiver, tx_sender)) {
106101
Ok(coro) => coro,
107102
Err(e) => {
108-
eprintln!("Failed to call ASGI app: {}", e);
109-
let _ = python_done_tx.send(Err(format!("Failed to call ASGI app: {}", e)));
103+
eprintln!("Failed to call ASGI app: {e}");
104+
let _ = python_done_tx.send(Err(format!("Failed to call ASGI app: {e}")));
110105
return;
111106
}
112107
};
@@ -115,8 +110,8 @@ pub async fn execute_asgi_http_scope(
115110
let asyncio = match py.import("asyncio") {
116111
Ok(module) => module,
117112
Err(e) => {
118-
eprintln!("Failed to import asyncio: {}", e);
119-
let _ = python_done_tx.send(Err(format!("Failed to import asyncio: {}", e)));
113+
eprintln!("Failed to import asyncio: {e}");
114+
let _ = python_done_tx.send(Err(format!("Failed to import asyncio: {e}")));
120115
return;
121116
}
122117
};
@@ -125,16 +120,16 @@ pub async fn execute_asgi_http_scope(
125120
let loop_ = match asyncio.call_method0("new_event_loop") {
126121
Ok(loop_) => loop_,
127122
Err(e) => {
128-
eprintln!("Failed to create event loop: {}", e);
129-
let _ = python_done_tx.send(Err(format!("Failed to create event loop: {}", e)));
123+
eprintln!("Failed to create event loop: {e}");
124+
let _ = python_done_tx.send(Err(format!("Failed to create event loop: {e}")));
130125
return;
131126
}
132127
};
133128

134129
// Set it as the current event loop
135130
if let Err(e) = asyncio.call_method1("set_event_loop", (&loop_,)) {
136-
eprintln!("Failed to set event loop: {}", e);
137-
let _ = python_done_tx.send(Err(format!("Failed to set event loop: {}", e)));
131+
eprintln!("Failed to set event loop: {e}");
132+
let _ = python_done_tx.send(Err(format!("Failed to set event loop: {e}")));
138133
return;
139134
}
140135

@@ -149,7 +144,7 @@ pub async fn execute_asgi_http_scope(
149144
std::thread::sleep(std::time::Duration::from_millis(10));
150145

151146
let _ = python_done_tx.send(result.map(|_| ()).map_err(|e| {
152-
format!("Failed to run ASGI coroutine: {}", e)
147+
format!("Failed to run ASGI coroutine: {e}")
153148
}));
154149
});
155150
});
@@ -193,5 +188,5 @@ pub async fn execute_asgi_http_scope(
193188

194189
builder
195190
.body(BytesMut::from(&body[..]))
196-
.map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(format!("Failed to build response: {}", e)))
191+
.map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(format!("Failed to build response: {e}")))
197192
}

0 commit comments

Comments
 (0)