Skip to content

Commit 243b298

Browse files
clippy
1 parent c1aec3f commit 243b298

File tree

3 files changed

+30
-36
lines changed

3 files changed

+30
-36
lines changed

src/pipelines/web/server/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
mod server;
1+
mod ws;
22
mod ws_actor;
33

4-
pub use server::*;
4+
pub use ws::*;
55
pub use ws_actor::*;

src/pipelines/web/server/server.rs renamed to src/pipelines/web/server/ws.rs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ async fn web_socket_route(req: HttpRequest, stream: web::Payload) -> Result<Http
2222
ws::start(
2323
WsActor {
2424
heartbeat: Instant::now(),
25-
rx: if let Some(rx) = &state.rx {
26-
Some(rx.clone())
27-
} else {
28-
None
29-
},
25+
rx: state.rx.as_ref().cloned(),
3026
},
3127
&req,
3228
stream,
@@ -38,39 +34,37 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Error> {
3834
let path = req.uri().path();
3935
let mut path = PathBuf::from(&path[1..]); // rm / from path
4036
let state: &WebServerState = req.app_data().unwrap();
41-
if {
42-
// if uri contains an extension then its a static file
43-
if let Some(ext) = path.extension() {
44-
let ext = ext.to_str().unwrap();
45-
// if extension is html then serve index.html
46-
let is_html = ext == "html";
47-
if !is_html {
48-
//check if file exists in output dir
49-
let output_path = PathBuf::from(&state.output_dir).join(&path);
50-
if output_path.exists() {
51-
path = output_path;
52-
} else if let Some(public_dir) = &state.public_dir {
53-
path = PathBuf::from(public_dir).join(&path);
54-
} else {
55-
return Ok(HttpResponse::new(StatusCode::NOT_FOUND));
56-
}
37+
// if uri contains an extension then its a static file
38+
if if let Some(ext) = path.extension() {
39+
let ext = ext.to_str().unwrap();
40+
// if extension is html then serve index.html
41+
let is_html = ext == "html";
42+
if !is_html {
43+
//check if file exists in output dir
44+
let output_path = PathBuf::from(&state.output_dir).join(&path);
45+
if output_path.exists() {
46+
path = output_path;
47+
} else if let Some(public_dir) = &state.public_dir {
48+
path = PathBuf::from(public_dir).join(&path);
49+
} else {
50+
return Ok(HttpResponse::new(StatusCode::NOT_FOUND));
5751
}
58-
is_html
59-
} else {
60-
// if path has no extension then serve html
61-
true
6252
}
53+
is_html
54+
} else {
55+
// if path has no extension then serve html
56+
true
6357
} {
6458
path = PathBuf::from(&state.output_dir).join("index.html")
6559
}
6660
// if path exist then serve it
67-
return if path.exists() {
61+
if path.exists() {
6862
Ok(actix_files::NamedFile::open(path)?
6963
.prefer_utf8(true)
7064
.into_response(&req))
7165
} else {
7266
Ok(HttpResponse::new(StatusCode::NOT_FOUND))
73-
};
67+
}
7468
}
7569

7670
pub fn start_web_server(

src/pipelines/web/web_pipeline.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ impl WebPipeline {
141141
let mut watcher =
142142
RecommendedWatcher::new(move |res: notify::Result<event::Event>| match res {
143143
Ok(event) => {
144-
if let event::EventKind::Modify(modify_event) = &event.kind {
145-
if let event::ModifyKind::Data(_) = modify_event {
146-
tx.send(()).unwrap();
147-
}
144+
if let event::EventKind::Modify(event::ModifyKind::Data(_)) =
145+
&event.kind
146+
{
147+
tx.send(()).unwrap();
148148
}
149149
}
150150
Err(e) => error!("Error while watching dir\n{}", e),
@@ -248,7 +248,7 @@ impl WebPipeline {
248248
}
249249
exec_cmd("cargo", &args, Some(&self.args.project_dir), None)
250250
.await
251-
.with_context(|| format!("error running cargo to build for web"))?;
251+
.context("error running cargo to build for web")?;
252252
Ok(())
253253
}
254254

@@ -257,7 +257,7 @@ impl WebPipeline {
257257
let web_subcmd = self.args.sub_cmd.as_web()?;
258258
exec_cmd(
259259
"wasm-bindgen",
260-
&vec![
260+
&[
261261
self.generate_path_to_target_wasm()
262262
.unwrap()
263263
.to_str()
@@ -278,7 +278,7 @@ impl WebPipeline {
278278
None,
279279
)
280280
.await
281-
.with_context(|| format!("error running cargo-bindgen. Make sure it is in path. Consider Installing it using `cargo install wasm-bindgen-cli`"))?;
281+
.context("error running cargo-bindgen. Make sure it is in path. Consider Installing it using `cargo install wasm-bindgen-cli`")?;
282282
Ok(())
283283
}
284284

0 commit comments

Comments
 (0)