Skip to content

Commit

Permalink
chore: Use let _ = ... to replace result.ok(). (#954)
Browse files Browse the repository at this point in the history
* chore: Use `let _ = ...` to replace `result.ok()`.

* clippy
  • Loading branch information
chrislearn authored Oct 11, 2024
1 parent 8183989 commit 30639ed
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 49 deletions.
2 changes: 1 addition & 1 deletion crates/core/src/catcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ pub fn write_error_default(req: &Request, res: &mut Response, footer: Option<&st
header::CONTENT_TYPE,
format.to_string().parse().expect("invalid `Content-Type`"),
);
res.write_body(data).ok();
let _ = res.write_body(data);
}

#[cfg(test)]
Expand Down
12 changes: 6 additions & 6 deletions crates/core/src/conn/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl HttpBuilder {

// Init graceful shutdown for connection (`GOAWAY` for `HTTP/2` or disabling `keep-alive` for `HTTP/1`)
Pin::new(&mut conn).graceful_shutdown();
conn.await.ok();
let _ = conn.await;
}
}
}
Expand All @@ -144,7 +144,7 @@ impl HttpBuilder {

// Init graceful shutdown for connection (`GOAWAY` for `HTTP/2` or disabling `keep-alive` for `HTTP/1`)
Pin::new(&mut conn).graceful_shutdown();
conn.await.ok();
let _ = conn.await;
}
}
}
Expand All @@ -160,7 +160,7 @@ impl HttpBuilder {
}
}
(None, None) => {
conn.await.ok();
let _ = conn.await;
}
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ impl HttpBuilder {

// Init graceful shutdown for connection (`GOAWAY` for `HTTP/2` or disabling `keep-alive` for `HTTP/1`)
Pin::new(&mut conn).graceful_shutdown();
conn.await.ok();
let _ = conn.await;
}
}
}
Expand All @@ -206,7 +206,7 @@ impl HttpBuilder {

// Init graceful shutdown for connection (`GOAWAY` for `HTTP/2` or disabling `keep-alive` for `HTTP/1`)
Pin::new(&mut conn).graceful_shutdown();
conn.await.ok();
let _ = conn.await;
}
}
}
Expand All @@ -222,7 +222,7 @@ impl HttpBuilder {
}
}
(None, None) => {
conn.await.ok();
let _ = conn.await;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/http/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ impl Drop for FilePart {
let path = self.path.clone();
let temp_dir = temp_dir.to_owned();
tokio::task::spawn_blocking(move || {
std::fs::remove_file(&path).ok();
std::fs::remove_dir(temp_dir).ok();
let _ = std::fs::remove_file(&path);
let _ = std::fs::remove_dir(temp_dir);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/serde/flat_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<'de> Deserializer<'de> for FlatValue<'de> {
{
let mut items = std::mem::take(&mut self.0);
let single_mode = if items.len() == 1 {
if let Some(item) = items.get(0) {
if let Some(item) = items.first() {
item.0.starts_with('[') && item.0.ends_with(']')
} else {
false
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/serde/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ where
match ctype.subtype() {
mime::WWW_FORM_URLENCODED | mime::FORM_DATA => {
if metadata.has_body_required() {
req.form_data().await.ok();
let _ = req.form_data().await;
}
}
mime::JSON => {
if metadata.has_body_required() {
req.payload().await.ok();
let _ = req.payload().await;
}
}
_ => {}
Expand Down
10 changes: 5 additions & 5 deletions crates/core/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl ServerHandle {
///
/// Call this function will stop server immediately.
pub fn stop_forcible(&self) {
self.tx_cmd.send(ServerCommand::StopForcible).ok();
let _ = self.tx_cmd.send(ServerCommand::StopForcible);
}

/// Graceful stop server.
Expand Down Expand Up @@ -81,7 +81,7 @@ impl ServerHandle {
/// }
/// ```
pub fn stop_graceful(&self, timeout: impl Into<Option<Duration>>) {
self.tx_cmd.send(ServerCommand::StopGraceful(timeout.into())).ok();
let _ = self.tx_cmd.send(ServerCommand::StopGraceful(timeout.into()));
}
}

Expand Down Expand Up @@ -159,7 +159,7 @@ impl<A: Acceptor + Send> Server<A> {
///
/// Call this function will stop server immediately.
pub fn stop_forcible(&self) {
self.tx_cmd.send(ServerCommand::StopForcible).ok();
let _ = self.tx_cmd.send(ServerCommand::StopForcible);
}

/// Graceful stop server.
Expand All @@ -168,7 +168,7 @@ impl<A: Acceptor + Send> Server<A> {
/// You can specify a timeout to force stop server.
/// If `timeout` is `None`, it will wait util all connections are closed.
pub fn stop_graceful(&self, timeout: impl Into<Option<Duration>>) {
self.tx_cmd.send(ServerCommand::StopGraceful(timeout.into())).ok();
let _ = self.tx_cmd.send(ServerCommand::StopGraceful(timeout.into()));
}
}

Expand Down Expand Up @@ -382,7 +382,7 @@ impl<A: Acceptor + Send> Server<A> {
let builder = builder.clone();

tokio::spawn(async move {
conn.serve(handler, builder, None).await.ok();
let _ = conn.serve(handler, builder, None).await;
});
},
Err(e) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/extra/src/request_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl Handler for RequestId {
return;
}
let id = self.generator.generate(req, depot);
req.add_header(self.header_name.clone(), &id, true).ok();
let _ = req.add_header(self.header_name.clone(), &id, true);
depot.insert(REQUST_ID_KEY, id);
}
}
2 changes: 1 addition & 1 deletion crates/jwt-auth/src/oidc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl OidcDecoder {
tracing::info!("Spawning Task to re-validate JWKS");
let a = self.clone();
tokio::task::spawn(async move {
a.update_cache().await.ok();
let _ = a.update_cache().await;
a.cache_state.set_is_revalidating(false);
a.notifier.notify_waiters();
});
Expand Down
2 changes: 1 addition & 1 deletion crates/macros/src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl Parse for ExtractFieldInfo {
return Err(input.error("unexpected attribute"));
}
}
input.parse::<Token![,]>().ok();
let _ = input.parse::<Token![,]>();
}
Ok(extract)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oapi-macros/src/parameter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Parse for ValueParameter<'_> {

if input.fork().parse::<ParameterIn>().is_ok() {
parameter.parameter_in = Some(input.parse()?);
input.parse::<Token![,]>().ok();
let _ = input.parse::<Token![,]>();
}

let (schema_features, parameter_features) = input
Expand Down
2 changes: 1 addition & 1 deletion crates/oapi/docs/derive_to_response.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl Scribe for PersonResponse {
fn render(self, res: &mut Response) {
res.headers_mut()
.insert(CONTENT_TYPE, HeaderValue::from_static("text/plain; charset=utf-8"));
res.write_body(self.value).ok();
let _ = res.write_body(self.value);
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oapi/docs/derive_to_responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl Scribe for UserResponses {
fn render(self, res: &mut Response) {
res.headers_mut()
.insert(CONTENT_TYPE, HeaderValue::from_static("text/plain; charset=utf-8"));
res.write_body(format!("{self:#?}")).ok();
let _ = res.write_body(format!("{self:#?}"));
}
}

Expand Down
38 changes: 16 additions & 22 deletions crates/serve-static/src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,25 +507,23 @@ fn list_xml(current: &CurrentInfo) -> String {
} else {
let format = format_description!("[year]-[month]-[day] [hour]:[minute]:[second]");
for dir in &current.dirs {
write!(
let _ = write!(
ftxt,
"<dir><name>{}</name><modified>{}</modified><link>{}</link></dir>",
dir.name,
dir.modified.format(&format).expect("format time failed"),
encode_url_path(&dir.name),
)
.ok();
);
}
for file in &current.files {
write!(
let _ = write!(
ftxt,
"<file><name>{}</name><modified>{}</modified><size>{}</size><link>{}</link></file>",
file.name,
file.modified.format(&format).expect("format time failed"),
file.size,
encode_url_path(&file.name),
)
.ok();
);
}
}
ftxt.push_str("</list>");
Expand Down Expand Up @@ -578,48 +576,44 @@ fn list_html(current: &CurrentInfo) -> String {
header_links(&current.path)
);
if current.dirs.is_empty() && current.files.is_empty() {
write!(ftxt, "<p>No files</p>").ok();
let _ = write!(ftxt, "<p>No files</p>");
} else {
write!(ftxt, "<table><tr><th>").ok();
let _ = write!(ftxt, "<table><tr><th>");
if !(current.path.is_empty() || current.path == "/") {
write!(ftxt, "<a href=\"../\">[..]</a>").ok();
let _ = write!(ftxt, "<a href=\"../\">[..]</a>");
}
write!(
let _ = write!(
ftxt,
"</th><th>Name</th><th>Last modified</th><th>Size</th></tr>"
)
.ok();
);
let format = format_description!("[year]-[month]-[day] [hour]:[minute]:[second]");
for dir in &current.dirs {
write!(
let _ = write!(
ftxt,
r#"<tr><td>{}</td><td><a href="./{}/">{}</a></td><td>{}</td><td></td></tr>"#,
DIR_ICON,
encode_url_path(&dir.name),
dir.name,
dir.modified.format(&format).expect("format time failed"),
)
.ok();
);
}
for file in &current.files {
write!(
let _ = write!(
ftxt,
r#"<tr><td>{}</td><td><a href="./{}">{}</a></td><td>{}</td><td>{}</td></tr>"#,
FILE_ICON,
encode_url_path(&file.name),
file.name,
file.modified.format(&format).expect("format time failed"),
human_size(file.size)
)
.ok();
);
}
write!(ftxt, "</table>").ok();
let _ = write!(ftxt, "</table>");
}
write!(
let _ = write!(
ftxt,
r#"<hr/><footer><a href="https://salvo.rs" target="_blank">salvo</a></footer></body>"#
)
.ok();
);
ftxt
}
#[inline]
Expand Down
4 changes: 2 additions & 2 deletions crates/serve-static/src/embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ fn render_embedded_data(

match data {
Cow::Borrowed(data) => {
res.write_body(data).ok();
let _ = res.write_body(data);
}
Cow::Owned(data) => {
res.write_body(data).ok();
let _ = res.write_body(data);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions examples/otel-jaeger/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ impl Exporter {
let mut body = Vec::new();
match encoder.encode(&metric_families, &mut body) {
Ok(()) => {
res.add_header(header::CONTENT_TYPE, "text/javascript; charset=utf-8", true)
.ok();
let _ = res.add_header(header::CONTENT_TYPE, "text/javascript; charset=utf-8", true);
res.body(body);
}
Err(_) => {
Expand Down

0 comments on commit 30639ed

Please sign in to comment.