Skip to content

Commit 2f37374

Browse files
committed
refactor: fixed clippy lints
1 parent 9d2a729 commit 2f37374

File tree

4 files changed

+38
-46
lines changed

4 files changed

+38
-46
lines changed

packages/perseus-cli/src/serve.rs

+33-35
Original file line numberDiff line numberDiff line change
@@ -69,62 +69,60 @@ fn build_server(
6969
let sb_spinner = spinners.insert(num_steps - 1, ProgressBar::new_spinner());
7070
let sb_spinner = cfg_spinner(sb_spinner, &sb_msg);
7171
let sb_target = target;
72-
let sb_thread =
73-
spawn_thread(move || {
74-
let (stdout, _stderr) = handle_exit_code!(run_stage(
72+
let sb_thread = spawn_thread(move || {
73+
let (stdout, _stderr) = handle_exit_code!(run_stage(
7574
vec![&format!(
7675
// This sets Cargo to tell us everything, including the executable path to the server
77-
"{} build --message-format json {} {}",
76+
"{} build --message-format json --features integration-{} {} --no-default-features {}",
7877
env::var("PERSEUS_CARGO_PATH").unwrap_or_else(|_| "cargo".to_string()),
7978
// Enable the appropriate integration
80-
format!(
81-
"--features integration-{} {} --no-default-features",
82-
integration.to_string(),
83-
// We'll also handle whether or not it's standalone because that goes under the `--features` flag
84-
if is_standalone {
85-
"--features standalone"
86-
} else {
87-
""
88-
}
89-
),
79+
integration.to_string(),
80+
// We'll also handle whether or not it's standalone because that goes under the `--features` flag
81+
if is_standalone {
82+
"--features standalone"
83+
} else {
84+
""
85+
},
9086
if is_release { "--release" } else { "" },
9187
)],
9288
&sb_target,
9389
&sb_spinner,
9490
&sb_msg
9591
)?);
9692

97-
let msgs: Vec<&str> = stdout.trim().split('\n').collect();
98-
// If we got to here, the exit code was 0 and everything should've worked
99-
// The last message will just tell us that the build finished, the second-last one will tell us the executable path
100-
let msg = msgs.get(msgs.len() - 2);
101-
let msg = match msg {
102-
// We'll parse it as a Serde `Value`, we don't need to know everything that's in there
103-
Some(msg) => serde_json::from_str::<serde_json::Value>(msg)
104-
.map_err(|err| ExecutionError::GetServerExecutableFailed { source: err })?,
105-
None => return Err(ExecutionError::ServerExectutableMsgNotFound),
106-
};
107-
let server_exec_path = msg.get("executable");
108-
let server_exec_path = match server_exec_path {
93+
let msgs: Vec<&str> = stdout.trim().split('\n').collect();
94+
// If we got to here, the exit code was 0 and everything should've worked
95+
// The last message will just tell us that the build finished, the second-last one will tell us the executable path
96+
let msg = msgs.get(msgs.len() - 2);
97+
let msg = match msg {
98+
// We'll parse it as a Serde `Value`, we don't need to know everything that's in there
99+
Some(msg) => serde_json::from_str::<serde_json::Value>(msg)
100+
.map_err(|err| ExecutionError::GetServerExecutableFailed { source: err })?,
101+
None => return Err(ExecutionError::ServerExectutableMsgNotFound),
102+
};
103+
let server_exec_path = msg.get("executable");
104+
let server_exec_path = match server_exec_path {
109105
// We'll parse it as a Serde `Value`, we don't need to know everything that's in there
110106
Some(server_exec_path) => match server_exec_path.as_str() {
111107
Some(server_exec_path) => server_exec_path,
112-
None => return Err(ExecutionError::ParseServerExecutableFailed {
113-
err: "expected 'executable' field to be string".to_string()
114-
}),
108+
None => {
109+
return Err(ExecutionError::ParseServerExecutableFailed {
110+
err: "expected 'executable' field to be string".to_string(),
111+
})
112+
}
115113
},
116114
None => return Err(ExecutionError::ParseServerExecutableFailed {
117115
err: "expected 'executable' field in JSON map in second-last message, not present"
118-
.to_string()
116+
.to_string(),
119117
}),
120118
};
121119

122-
// And now the main thread needs to know about this
123-
let mut exec_val = exec.lock().unwrap();
124-
*exec_val = server_exec_path.to_string();
120+
// And now the main thread needs to know about this
121+
let mut exec_val = exec.lock().unwrap();
122+
*exec_val = server_exec_path.to_string();
125123

126-
Ok(0)
127-
});
124+
Ok(0)
125+
});
128126

129127
Ok(sb_thread)
130128
}

packages/perseus-cli/src/snoop.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,10 @@ pub fn snoop_server(dir: PathBuf, opts: SnoopServeOpts) -> Result<i32, Execution
4343
let target = dir.join(".perseus/server");
4444
run_cmd_directly(
4545
format!(
46-
"{} run {}",
46+
"{} run --features integration-{} --no-default-features",
4747
env::var("PERSEUS_CARGO_PATH").unwrap_or_else(|_| "cargo".to_string()),
4848
// Enable the appropriate feature for a non-default server integration
49-
format!(
50-
"--features integration-{} --no-default-features",
51-
opts.integration.to_string()
52-
)
49+
opts.integration.to_string()
5350
),
5451
&target,
5552
)

packages/perseus/src/server/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ pub async fn get_page_for_template<M: MutableStore, T: TranslationsManager>(
278278
path = "index";
279279
}
280280
// Remove `/` from the path by encoding it as a URL (that's what we store) and add the locale
281-
let path_encoded = format!("{}-{}", locale, urlencoding::encode(path).to_string());
281+
let path_encoded = format!("{}-{}", locale, urlencoding::encode(path));
282282
let path_with_locale = get_path_with_locale(path, &translator);
283283

284284
// Only a single string of HTML is needed, and it will be overridden if necessary (priorities system)

packages/perseus/src/shell.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ pub fn get_initial_state() -> InitialState {
118118
Err(err) => ErrorPageData {
119119
url: "[current]".to_string(),
120120
status: 500,
121-
err: format!(
122-
"couldn't serialize error from server: '{}'",
123-
err.to_string()
124-
),
121+
err: format!("couldn't serialize error from server: '{}'", err),
125122
},
126123
};
127124
InitialState::Error(err_page_data)
@@ -407,7 +404,7 @@ pub async fn app_shell(
407404
"{}/.perseus/page/{}/{}.json?template_name={}&was_incremental_match={}",
408405
get_path_prefix_client(),
409406
locale,
410-
path.to_string(),
407+
path,
411408
template.get_path(),
412409
was_incremental_match
413410
);

0 commit comments

Comments
 (0)