Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
The remaining "unneeded unit expression" is not out fault:
rustwasm/wasm-bindgen#2774
  • Loading branch information
tv42 committed Mar 22, 2022
1 parent 04582ff commit 4e898c5
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 59 deletions.
2 changes: 1 addition & 1 deletion embed/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn main() -> Result<(), anyhow::Error> {
println!("cargo:warning=see {}", out_dir);

// this creates <wasm_out>/wasm.js & wasm_bg.wasm
let wasm_out = out_dir.to_owned() + "/wasm";
let wasm_out = out_dir + "/wasm";
create_dir_if_not_exist(&wasm_out)?;
let status = Command::new(wasm_bindgen)
.args(&[
Expand Down
4 changes: 2 additions & 2 deletions embed/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::{concat, env, include_bytes};

pub fn wasm() -> Cursor<&'static [u8]> {
let bytes = include_bytes!(concat!(env!("OUT_DIR"), "/wasm/choosy_frontend_bg.wasm"));
return Cursor::new(bytes);
Cursor::new(bytes)
}

pub fn wasm_js() -> Cursor<&'static [u8]> {
let bytes = include_bytes!(concat!(env!("OUT_DIR"), "/wasm/choosy_frontend.js"));
return Cursor::new(bytes);
Cursor::new(bytes)
}
2 changes: 1 addition & 1 deletion frontend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl Component for Model {
//
// https://github.com/yewstack/yew/issues/1851
value={self.search.clone()}
oninput={ctx.link().callback(|e: InputEvent| Msg::UpdateSearch{s: e.data().unwrap_or("".to_string())})}
oninput={ctx.link().callback(|e: InputEvent| Msg::UpdateSearch{s: e.data().unwrap_or_else(|| "".to_string())})}
style="width: 100%;"
/>
<ul>
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum WebSocketError {
#[derive(Debug)]
pub enum WebSocketSendError {
InvalidStateError(web_sys::DomException),
JSON(serde_json::Error),
Json(serde_json::Error),
}

pub struct WebSocket {
Expand All @@ -43,9 +43,9 @@ impl WebSocket {
on_close: impl 'static + FnOnce(web_sys::CloseEvent),
on_message: impl 'static + Fn(web_sys::MessageEvent),
) -> Result<Self, WebSocketError> {
return web_sys::WebSocket::new(url)
web_sys::WebSocket::new(url)
.map_err(js_sys::SyntaxError::unchecked_from_js)
.map_err(|error| WebSocketError::BadUrl(error))
.map_err(WebSocketError::BadUrl)
.map(|inner| -> WebSocket {
// TODO could use Blob and stream to serde_json
inner.set_binary_type(web_sys::BinaryType::Arraybuffer);
Expand All @@ -71,17 +71,17 @@ impl WebSocket {
on_close,
on_message,
}
});
})
}

pub fn send_json<M: serde::ser::Serialize>(
&self,
message: M,
) -> Result<(), WebSocketSendError> {
let buf = serde_json::to_vec(&message).map_err(|error| WebSocketSendError::JSON(error))?;
let buf = serde_json::to_vec(&message).map_err(WebSocketSendError::Json)?;
self.inner
.send_with_u8_array(&buf)
.map_err(web_sys::DomException::unchecked_from_js)
.map_err(|error| WebSocketSendError::InvalidStateError(error))
.map_err(WebSocketSendError::InvalidStateError)
}
}
25 changes: 12 additions & 13 deletions mpv_remote/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Config {
task::Builder::new()
.name("mpv-ipc".to_string())
.spawn(async move { ipc.read_from_mpv().await })
.map_err(|e| StartError::SpawningTask(e))?
.map_err(StartError::SpawningTask)?
};

let mpv = MPV {
Expand All @@ -116,8 +116,7 @@ impl MPV {

pub async fn events(&self) -> async_broadcast::Receiver<MPVEvent> {
let guard = self.ipc.events_receiver.lock().await;
let r = guard.clone();
r
guard.clone()
}
}

Expand Down Expand Up @@ -154,7 +153,7 @@ impl IPCState {
.expect("internal error: broadcast channel cannot be closed yet");
// we're forced to keep one receiver just to be able to clone it on demand, but that means items are left buffered when idle. consume from that sender, just to clear room. https://github.com/smol-rs/async-broadcast/issues/2
let mut guard = self.events_receiver.lock().await;
while let Ok(_) = guard.try_recv() {
while guard.try_recv().is_ok() {
// nothing
}
}
Expand All @@ -174,7 +173,7 @@ impl IPCState {
});
}
Some(sender) => {
let result = response.result.map_err(|msg| IPCError::FromMPV(msg));
let result = response.result.map_err(IPCError::FromMPV);
debug!("sending result", {
result: log::kv::Value::capture_debug(&result)
});
Expand Down Expand Up @@ -219,16 +218,16 @@ impl MPV {
let mut guard = self.ipc.pending.lock().await;
guard.insert()
};
if let Some(id) = id_option {
if let Some(request_id) = id_option {
// send
let wire_command = Command {
request_id: id,
command: command,
request_id,
command,
async_: true,
};
let mut wire_data =
serde_json::to_vec(&wire_command).map_err(|e| IPCError::JSONSerialize(e))?;
wire_data.push('\n' as u8);
serde_json::to_vec(&wire_command).map_err(IPCError::JSONSerialize)?;
wire_data.push(b'\n');
debug!("sending command", {
// RUST-WART i can only get a numeric display out of this!
data: log::kv::Value::capture_debug(&wire_data),
Expand All @@ -237,7 +236,7 @@ impl MPV {
guard
.write_all(&wire_data)
.await
.map_err(|e| IPCError::Network(e))?
.map_err(IPCError::Network)?
}
match receiver.await {
Err(error) => match error {
Expand Down Expand Up @@ -269,12 +268,12 @@ impl MPV {
let _ignore_kill_error = libc::kill(self.child.id() as i32, libc::SIGTERM);
}

self.ipc_task.await.map_err(|e| CloseError::TaskError(e))?;
self.ipc_task.await.map_err(CloseError::TaskError)?;
let exit_status = self
.child
.status()
.await
.map_err(|e| CloseError::ProcessError(e))?;
.map_err(CloseError::ProcessError)?;
if !exit_status.success() {
return Err(CloseError::MPVExitStatus(exit_status));
}
Expand Down
1 change: 0 additions & 1 deletion mpv_remote/src/messages.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// TODO these types may be public, but they are most definitely not stable. exhaustive match arms will need updating regularly, and if we get Unknown variants working, things will move from Unknown to strongly-typed variants over time.

use serde::{Deserialize, Serialize};
use serde_json;
use std::time;

mod serde_duration;
Expand Down
1 change: 0 additions & 1 deletion mpv_remote/src/messages/serde_duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// https://serde.rs/custom-date-format.html

use serde;
use serde::Deserialize;
use std::time;

Expand Down
1 change: 0 additions & 1 deletion mpv_remote/src/messages/serde_ipcresult.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use serde;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion mpv_remote/src/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<T> Pending<T> {
}
None => {
drop(sender);
return (None, receiver);
(None, receiver)
}
}
}
Expand Down
18 changes: 8 additions & 10 deletions server/src/file_scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ fn is_interesting(entry: &DirEntry) -> bool {
None => return false,
Some(ext) => ext,
};
// rust is being painful, Path::extension() is a Cow
match &*ext.to_string_lossy() {
"mkv" | "mp4" | "avi" | "ogm" | "wmv" | "m4v" | "rmvb" | "flv" | "mov" | "mpg" => true,
_ => false,
}
matches!(
// "" will never match anything we're interested in.
ext.to_str().unwrap_or(""),
"mkv" | "mp4" | "avi" | "ogm" | "wmv" | "m4v" | "rmvb" | "flv" | "mov" | "mpg"
)
}

pub fn scan(path: &Path) -> impl Iterator<Item = String> {
Expand All @@ -22,7 +22,7 @@ pub fn scan(path: &Path) -> impl Iterator<Item = String> {
}

let base = Arc::new(path.to_path_buf());
let walker = WalkDir::new(path)
WalkDir::new(path)
.max_open(20)
.same_file_system(true)
.into_iter()
Expand Down Expand Up @@ -66,13 +66,12 @@ pub fn scan(path: &Path) -> impl Iterator<Item = String> {
if !t.is_file() && !t.is_symlink() {
return false;
}
if !is_interesting(&entry) {
if !is_interesting(entry) {
return false;
}
true
})
.filter_map({
let base = base.clone();
move |entry| match entry.path().strip_prefix(&*base) {
Err(error) => {
log::warn!("file scanning found file in wrong subtree: {}", error);
Expand All @@ -84,6 +83,5 @@ pub fn scan(path: &Path) -> impl Iterator<Item = String> {
Some(p)
}
}
});
walker
})
}
37 changes: 16 additions & 21 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ use async_std::stream::StreamExt;
use async_std::sync::Arc;
use async_std::sync::Mutex;
use async_std::task;
use choosy_embed;
use choosy_protocol as proto;
use http_types::mime;
#[allow(unused_imports)]
use kv_log_macro::{debug, error, info, log, trace, warn};
use listenfd::ListenFd;
use mpv_remote::MPV;
use scopeguard;
use serde_json;
use std::collections::{BTreeMap, BTreeSet};
use std::path::{Path, PathBuf};
use std::time::Duration;
Expand Down Expand Up @@ -92,7 +89,7 @@ async fn ws_list_events(state: Arc<State>, conn: ws::Conn) -> tide::Result<()> {

// TODO Get rid of the batching, as we now stream events.
let batch = vec![proto::FileChange::Add {
name: String::from_utf8_lossy(&key.as_ref()).into_owned(),
name: String::from_utf8_lossy(key.as_ref()).into_owned(),
}];
sender.try_send(batch)?;
}
Expand All @@ -111,7 +108,7 @@ async fn ws_list_events(state: Arc<State>, conn: ws::Conn) -> tide::Result<()> {
// Then send buffered events.
{
for (key, event) in buffered_events.into_iter() {
let name = String::from_utf8_lossy(&key.as_ref()).into_owned();
let name = String::from_utf8_lossy(key.as_ref()).into_owned();
let change = match event {
sleigh::Event::Insert { key: _, value } => {
if value.exists {
Expand All @@ -134,15 +131,15 @@ async fn ws_list_events(state: Arc<State>, conn: ws::Conn) -> tide::Result<()> {
let event = result?;
let change = match event {
sleigh::Event::Insert { key, value } => {
let name = String::from_utf8_lossy(&key.as_ref()).into_owned();
let name = String::from_utf8_lossy(key.as_ref()).into_owned();
if value.exists {
proto::FileChange::Add { name }
} else {
proto::FileChange::Del { name }
}
}
sleigh::Event::Remove { key } => proto::FileChange::Del {
name: String::from_utf8_lossy(&key.as_ref()).into_owned(),
name: String::from_utf8_lossy(key.as_ref()).into_owned(),
},
};
let batch = vec![change];
Expand Down Expand Up @@ -295,18 +292,16 @@ async fn websocket_command(state: &Arc<State>, command: proto::WSCommand) {
//
// Try to get something where self.playing is a data structure
// that "becomes None" when this task exits.
match previous {
None => {
// no idea how that happened
debug!("internal error: playing is unexpectedly not set");
return;
}
Some(mpv) => match mpv.close().await {
Err(error) => warn!("mpv error", {
error: log::kv::Value::capture_error(&error),
}),
Ok(_) => {}
},
if previous.is_none() {
// no idea how that happened
debug!("internal error: playing is unexpectedly not set");
return;
}
let mpv = previous.unwrap();
if let Err(error) = mpv.close().await {
warn!("mpv error", {
error: log::kv::Value::capture_error(&error),
});
}
});
}
Expand Down Expand Up @@ -359,7 +354,7 @@ async fn main() -> anyhow::Result<()> {
let db = state.media.scan_prefix("");
let merge = itertools::merge_join_by(db, files, |result, file_path| match result {
Ok((key, _item)) => key.cmp(&sled::IVec::from(file_path.as_str())),
Err(_) => return std::cmp::Ordering::Less,
Err(_) => std::cmp::Ordering::Less,
});
for merged in merge {
// debug!("merge", { merged: log::kv::Value::capture_debug(&merged) });
Expand Down Expand Up @@ -429,7 +424,7 @@ async fn main() -> anyhow::Result<()> {
let listener = fds
.take_tcp_listener(0)
.context("LISTEN_FDS must set up listening sockets")?
.ok_or(anyhow::anyhow!("LISTEN_FDS must have set up a TCP socket"))?;
.ok_or_else(|| anyhow::anyhow!("LISTEN_FDS must have set up a TCP socket"))?;
app.listen(listener).await?;
Ok(())
}
2 changes: 1 addition & 1 deletion sleigh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ where
};
let dec: Result<V, Enc::Error> = Enc::deserialize(&buf);
match dec {
Err(error) => return Some(Err(GetError::Deserialize(error))),
Err(error) => Some(Err(GetError::Deserialize(error))),
Ok(item) => Some(Ok((key, item))),
}
}
Expand Down

0 comments on commit 4e898c5

Please sign in to comment.