diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-01-01 22:32:12 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-01-01 22:40:08 +0100 |
| commit | 1c8b7316503d3ab710d3d3ec241b85e76b9a42be (patch) | |
| tree | 95e85a9f7bd26b6901e6cbe5e9ca29f8d60053e5 | |
| parent | 67364577263943e815be9ba700c10845698e116d (diff) | |
| download | mum-1c8b7316503d3ab710d3d3ec241b85e76b9a42be.tar.gz | |
clippy pass
| -rw-r--r-- | mumctl/src/main.rs | 20 | ||||
| -rw-r--r-- | mumd/src/audio.rs | 2 | ||||
| -rw-r--r-- | mumd/src/command.rs | 6 | ||||
| -rw-r--r-- | mumd/src/network/udp.rs | 29 | ||||
| -rw-r--r-- | mumd/src/state.rs | 4 | ||||
| -rw-r--r-- | mumd/src/state/channel.rs | 10 | ||||
| -rw-r--r-- | mumd/src/state/server.rs | 2 | ||||
| -rw-r--r-- | mumlib/src/config.rs | 2 | ||||
| -rw-r--r-- | mumlib/src/state.rs | 18 |
9 files changed, 43 insertions, 50 deletions
diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 27e27c4..d43ff4f 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -204,11 +204,8 @@ fn main() { ); let stdin = std::io::stdin(); let response = stdin.lock().lines().next(); - match response.map(|e| e.map(|e| &e == "Y")) { - Some(Ok(true)) => { - config.write_default_cfg(true).unwrap(); - } - _ => {} + if let Some(Ok(true)) = response.map(|e| e.map(|e| &e == "Y")) { + config.write_default_cfg(true).unwrap(); } } else { config.write_default_cfg(false).unwrap(); @@ -234,7 +231,7 @@ fn process_matches(matches: ArgMatches, config: &mut Config, app: &mut App) -> R } else if let Some(matches) = matches.subcommand_matches("add") { match_server_add(matches, config); } else if let Some(_) = matches.subcommand_matches("list") { - if config.servers.len() == 0 { + if config.servers.is_empty() { warn!("No servers in config"); } let query = config @@ -409,8 +406,7 @@ fn match_server_connect(matches: &clap::ArgMatches<'_>, config: &mumlib::config: let port = server_config.port.unwrap_or(port); let username = server_config .username - .as_ref() - .map(|e| e.as_str()) + .as_deref() .or(username); if username.is_none() { error!("no username specified"); @@ -525,17 +521,17 @@ fn match_server_config(matches: &clap::ArgMatches<'_>, config: &mut mumlib::conf server .port .map(|s| format!("port: {}\n", s)) - .unwrap_or("".to_string()), + .unwrap_or_else(|| "".to_string()), server .username .as_ref() .map(|s| format!("username: {}\n", s)) - .unwrap_or("".to_string()), + .unwrap_or_else(|| "".to_string()), server .password .as_ref() .map(|s| format!("password: {}\n", s)) - .unwrap_or("".to_string()), + .unwrap_or_else(|| "".to_string()), ) } } else { @@ -664,4 +660,4 @@ impl Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "Unable to connect to mumd. Is mumd running?") } -}
\ No newline at end of file +} diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs index 0666268..0820147 100644 --- a/mumd/src/audio.rs +++ b/mumd/src/audio.rs @@ -16,7 +16,7 @@ use std::sync::{Arc, Mutex}; use tokio::sync::{mpsc, watch}; //TODO? move to mumlib -pub const EVENT_SOUNDS: &[(&'static [u8], NotificationEvents)] = &[ +pub const EVENT_SOUNDS: &[(&[u8], NotificationEvents)] = &[ (include_bytes!("resources/connect.wav"), NotificationEvents::ServerConnect), ( include_bytes!("resources/disconnect.wav"), diff --git a/mumd/src/command.rs b/mumd/src/command.rs index 330e3fc..9c8970c 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -1,11 +1,9 @@ use crate::state::{ExecutionContext, State}; +use crate::network::{tcp::{TcpEvent, TcpEventCallback}, udp::PingRequest}; -use crate::network::tcp::{TcpEvent, TcpEventCallback}; use ipc_channel::ipc::IpcSender; use log::*; -use mumble_protocol::ping::PongPacket; use mumlib::command::{Command, CommandResponse}; -use std::net::SocketAddr; use std::sync::{Arc, Mutex}; use tokio::sync::{mpsc, oneshot}; @@ -16,7 +14,7 @@ pub async fn handle( IpcSender<mumlib::error::Result<Option<CommandResponse>>>, )>, tcp_event_register_sender: mpsc::UnboundedSender<(TcpEvent, TcpEventCallback)>, - ping_request_sender: mpsc::UnboundedSender<(u64, SocketAddr, Box<dyn FnOnce(PongPacket)>)>, + ping_request_sender: mpsc::UnboundedSender<PingRequest>, ) { debug!("Begin listening for commands"); while let Some((command, response_sender)) = command_receiver.recv().await { diff --git a/mumd/src/network/udp.rs b/mumd/src/network/udp.rs index b592a60..f7eeb62 100644 --- a/mumd/src/network/udp.rs +++ b/mumd/src/network/udp.rs @@ -1,10 +1,10 @@ use crate::network::ConnectionInfo; use crate::state::{State, StatePhase}; -use log::*; use bytes::Bytes; use futures::{join, pin_mut, select, FutureExt, SinkExt, StreamExt}; use futures_util::stream::{SplitSink, SplitStream}; +use log::*; use mumble_protocol::crypt::ClientCryptState; use mumble_protocol::ping::{PingPacket, PongPacket}; use mumble_protocol::voice::{VoicePacket, VoicePacketPayload}; @@ -18,6 +18,8 @@ use tokio::net::UdpSocket; use tokio::sync::{mpsc, oneshot, watch}; use tokio_util::udp::UdpFramed; +pub type PingRequest = (u64, SocketAddr, Box<dyn FnOnce(PongPacket)>); + type UdpSender = SplitSink<UdpFramed<ClientCryptState>, (VoicePacket<Serverbound>, SocketAddr)>; type UdpReceiver = SplitStream<UdpFramed<ClientCryptState>>; @@ -89,17 +91,14 @@ async fn new_crypt_state( source: Arc<Mutex<UdpReceiver>>, ) { loop { - match crypt_state.recv().await { - Some(crypt_state) => { - info!("Received new crypt state"); - let udp_socket = UdpSocket::bind((Ipv6Addr::from(0u128), 0u16)) - .await - .expect("Failed to bind UDP socket"); - let (new_sink, new_source) = UdpFramed::new(udp_socket, crypt_state).split(); - *sink.lock().unwrap() = new_sink; - *source.lock().unwrap() = new_source; - }, - None => {}, + if let Some(crypt_state) = crypt_state.recv().await { + info!("Received new crypt state"); + let udp_socket = UdpSocket::bind((Ipv6Addr::from(0u128), 0u16)) + .await + .expect("Failed to bind UDP socket"); + let (new_sink, new_source) = UdpFramed::new(udp_socket, crypt_state).split(); + *sink.lock().unwrap() = new_sink; + *source.lock().unwrap() = new_source; } } } @@ -256,11 +255,7 @@ async fn send_voice( } pub async fn handle_pings( - mut ping_request_receiver: mpsc::UnboundedReceiver<( - u64, - SocketAddr, - Box<dyn FnOnce(PongPacket)>, - )>, + mut ping_request_receiver: mpsc::UnboundedReceiver<PingRequest>, ) { let udp_socket = UdpSocket::bind((Ipv6Addr::from(0u128), 0u16)) .await diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 85e5449..546f7d1 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -219,7 +219,7 @@ impl State { .unwrap() .users_mut() .iter_mut() - .find(|(_, user)| user.name() == &string); + .find(|(_, user)| user.name() == string); let (id, user) = match id { Some(id) => (*id.0, id.1), @@ -408,7 +408,7 @@ impl State { .unwrap() .users() .iter() - .find(|e| e.1.name() == &string) + .find(|e| e.1.name() == string) .map(|e| *e.0) { None => return now!(Err(Error::InvalidUsernameError(string))), diff --git a/mumd/src/state/channel.rs b/mumd/src/state/channel.rs index 8bbf919..5b6d669 100644 --- a/mumd/src/state/channel.rs +++ b/mumd/src/state/channel.rs @@ -88,7 +88,7 @@ impl<'a> ProtoTree<'a> { users: Vec::new(), }); pt.channel = Some(channel); - pt.users = users.get(&node).map(|e| e.clone()).unwrap_or(Vec::new()); + pt.users = users.get(&node).cloned().unwrap_or_default(); } longer => { self.children @@ -135,7 +135,7 @@ pub fn into_channel( for user in users.values() { channel_lookup .entry(user.channel()) - .or_insert(Vec::new()) + .or_insert_with(Vec::new) .push(user); } @@ -148,7 +148,7 @@ pub fn into_channel( } walk.reverse(); - if walk.len() > 0 { + if !walk.is_empty() { walks.push((walk, channel)); } } @@ -159,8 +159,8 @@ pub fn into_channel( children: HashMap::new(), users: channel_lookup .get(&0) - .map(|e| e.clone()) - .unwrap_or(Vec::new()), + .cloned() + .unwrap_or_default(), }; for (walk, channel) in walks { diff --git a/mumd/src/state/server.rs b/mumd/src/state/server.rs index a065df0..8a256b6 100644 --- a/mumd/src/state/server.rs +++ b/mumd/src/state/server.rs @@ -107,7 +107,7 @@ impl Server { } pub fn username(&self) -> Option<&str> { - self.username.as_ref().map(|e| e.as_str()) + self.username.as_deref() } pub fn username_mut(&mut self) -> &mut Option<String> { diff --git a/mumlib/src/config.rs b/mumlib/src/config.rs index 3a2fa27..5987ab9 100644 --- a/mumlib/src/config.rs +++ b/mumlib/src/config.rs @@ -138,7 +138,7 @@ impl TryFrom<TOMLConfig> for Config { .collect() }) .transpose()? - .unwrap_or(Vec::new()), + .unwrap_or_default(), }) } } diff --git a/mumlib/src/state.rs b/mumlib/src/state.rs index 0f1cef2..9c71b47 100644 --- a/mumlib/src/state.rs +++ b/mumlib/src/state.rs @@ -24,10 +24,10 @@ impl Channel { pub fn iter(&self) -> Iter<'_> { Iter { me: Some(&self), - channel: if self.children.len() > 0 { - Some(0) - } else { + channel: if self.children.is_empty() { None + } else { + Some(0) }, channels: self.children.iter().map(|e| e.iter()).collect(), } @@ -36,12 +36,16 @@ impl Channel { pub fn users_iter(&self) -> UsersIter<'_> { UsersIter { channels: self.children.iter().map(|e| e.users_iter()).collect(), - channel: if self.children.len() > 0 { - Some(0) + channel: if self.children.is_empty() { + None } else { + Some(0) + }, + user: if self.users.is_empty() > 0 { None + } else { + Some(0) }, - user: if self.users.len() > 0 { Some(0) } else { None }, users: &self.users, } } @@ -152,4 +156,4 @@ impl Display for User { true_to_str!(self.deaf, "d") ) } -}
\ No newline at end of file +} |
