From 85c1f17d451cf30800ea2f027bcbd15074451a78 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 19:15:22 +0200 Subject: add elided-liftimes-in-paths lint --- mumd/src/main.rs | 2 ++ mumd/src/network/tcp.rs | 6 +++--- mumd/src/state.rs | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index bc72779..825251e 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -1,3 +1,5 @@ +#![warn(elided_lifetimes_in_paths)] + mod audio; mod client; mod command; diff --git a/mumd/src/network/tcp.rs b/mumd/src/network/tcp.rs index f620a32..1f226d8 100644 --- a/mumd/src/network/tcp.rs +++ b/mumd/src/network/tcp.rs @@ -31,8 +31,8 @@ type TcpSender = SplitSink< type TcpReceiver = SplitStream, ControlCodec>>; -pub(crate) type TcpEventCallback = Box; -pub(crate) type TcpEventSubscriber = Box bool>; //the bool indicates if it should be kept or not +pub(crate) type TcpEventCallback = Box)>; +pub(crate) type TcpEventSubscriber = Box) -> bool>; //the bool indicates if it should be kept or not /// Why the TCP was disconnected. #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] @@ -65,7 +65,7 @@ pub enum TcpEventData<'a> { } impl<'a> From<&TcpEventData<'a>> for TcpEvent { - fn from(t: &TcpEventData) -> Self { + fn from(t: &TcpEventData<'_>) -> Self { match t { TcpEventData::Connected(_) => TcpEvent::Connected, TcpEventData::Disconnected(reason) => TcpEvent::Disconnected(*reason), diff --git a/mumd/src/state.rs b/mumd/src/state.rs index d2d77b1..9d9e1c6 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -44,12 +44,12 @@ type Responses = Box Responses>)>), + TcpEventCallback(Vec<(TcpEvent, Box) -> Responses>)>), TcpEventSubscriber( TcpEvent, Box< dyn FnMut( - TcpEventData, + TcpEventData<'_>, &mut mpsc::UnboundedSender>>, ) -> bool, >, -- cgit v1.2.1 From 4c0abc2c1bf008812cdec448f50305611911cb5b Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 19:16:56 +0200 Subject: add keyword-idents lint --- mumd/src/main.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 825251e..f5b00c3 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -1,4 +1,5 @@ #![warn(elided_lifetimes_in_paths)] +#![deny(keyword_idents)] mod audio; mod client; -- cgit v1.2.1 From 90f5e8ef3c7aa61ccdb087073b2c0cf6ac52f1ee Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 19:17:45 +0200 Subject: add macro_use_extern_crate lint --- mumd/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index f5b00c3..e7a7945 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -1,5 +1,5 @@ #![warn(elided_lifetimes_in_paths)] -#![deny(keyword_idents)] +#![deny(keyword_idents, macro_use_extern_crate)] mod audio; mod client; -- cgit v1.2.1 From 1f41a6b9a439bab3f05e464d621eb3607116646e Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 19:19:31 +0200 Subject: add meta_variable_misuse lint --- mumd/src/main.rs | 2 +- mumd/src/state.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index e7a7945..4f611a4 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -1,4 +1,4 @@ -#![warn(elided_lifetimes_in_paths)] +#![warn(elided_lifetimes_in_paths, meta_variable_misuse)] #![deny(keyword_idents, macro_use_extern_crate)] mod audio; diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 9d9e1c6..38d54d3 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -29,7 +29,7 @@ use tokio::sync::{mpsc, watch}; macro_rules! at { ( $( $event:expr => $generator:expr ),+ $(,)? ) => { ExecutionContext::TcpEventCallback(vec![ - $( ($event, Box::new($generator)), )* + $( ($event, Box::new($generator)), )+ ]) }; } -- cgit v1.2.1 From f887f3a4f9953483c16cb4d47fbd3c5cd72f967b Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 19:19:58 +0200 Subject: add missing_abi lint --- mumd/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 4f611a4..8dc58df 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -1,5 +1,5 @@ #![warn(elided_lifetimes_in_paths, meta_variable_misuse)] -#![deny(keyword_idents, macro_use_extern_crate)] +#![deny(keyword_idents, macro_use_extern_crate, missing_abi)] mod audio; mod client; -- cgit v1.2.1 From 555b8195e651fcca8c906177c784c5c50a49475c Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 20:07:47 +0200 Subject: add missing_debug_implementations lint --- mumd/src/main.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 8dc58df..d592cec 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -1,4 +1,5 @@ #![warn(elided_lifetimes_in_paths, meta_variable_misuse)] +#![warn(missing_debug_implementations)] //doesn't seem to work #![deny(keyword_idents, macro_use_extern_crate, missing_abi)] mod audio; -- cgit v1.2.1 From 78e1e35da23466126ce3411793f8985ab333140c Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 20:08:47 +0200 Subject: move lints to separate lines --- mumd/src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index d592cec..514de7b 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -1,6 +1,9 @@ -#![warn(elided_lifetimes_in_paths, meta_variable_misuse)] +#![warn(elided_lifetimes_in_paths)] +#![warn(meta_variable_misuse)] #![warn(missing_debug_implementations)] //doesn't seem to work #![deny(keyword_idents, macro_use_extern_crate, missing_abi)] +#![deny(macro_use_extern_crate, missing_abi)] +#![deny(missing_abi)] mod audio; mod client; -- cgit v1.2.1 From 9f8f46a9f91840763e10fe1b603663e346970b79 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 20:10:15 +0200 Subject: oops --- mumd/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 514de7b..819402d 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -1,8 +1,8 @@ #![warn(elided_lifetimes_in_paths)] #![warn(meta_variable_misuse)] #![warn(missing_debug_implementations)] //doesn't seem to work -#![deny(keyword_idents, macro_use_extern_crate, missing_abi)] -#![deny(macro_use_extern_crate, missing_abi)] +#![deny(keyword_idents)] +#![deny(macro_use_extern_crate)] #![deny(missing_abi)] mod audio; -- cgit v1.2.1 From 9bc2bdc5dca1399fa75d20a18f1a2dfb8ab4e325 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 20:14:59 +0200 Subject: add single_use_lifetimes lint --- mumd/src/main.rs | 1 + mumd/src/network/tcp.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 819402d..29ea77f 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -1,6 +1,7 @@ #![warn(elided_lifetimes_in_paths)] #![warn(meta_variable_misuse)] #![warn(missing_debug_implementations)] //doesn't seem to work +#![warn(single_use_lifetimes)] #![deny(keyword_idents)] #![deny(macro_use_extern_crate)] #![deny(missing_abi)] diff --git a/mumd/src/network/tcp.rs b/mumd/src/network/tcp.rs index 1f226d8..a76814c 100644 --- a/mumd/src/network/tcp.rs +++ b/mumd/src/network/tcp.rs @@ -64,7 +64,7 @@ pub enum TcpEventData<'a> { TextMessage(&'a msgs::TextMessage), } -impl<'a> From<&TcpEventData<'a>> for TcpEvent { +impl From<&TcpEventData<'_>> for TcpEvent { fn from(t: &TcpEventData<'_>) -> Self { match t { TcpEventData::Connected(_) => TcpEvent::Connected, @@ -111,7 +111,7 @@ impl TcpEventQueue { /// Fires all callbacks related to a specific TCP event and removes them from the event queue. /// Also calls all event subscribers, but keeps them in the queue - pub fn resolve<'a>(&self, data: TcpEventData<'a>) { + pub fn resolve(&self, data: TcpEventData<'_>) { if let Some(vec) = self .callbacks .write() -- cgit v1.2.1 From 465f21da46a7194e25894043ca2cca9ba958e11c Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 20:48:54 +0200 Subject: add unreachable_pub lint and fix debug impl --- mumd/src/audio.rs | 10 ++++++++++ mumd/src/audio/input.rs | 12 ++++++++++++ mumd/src/audio/output.rs | 13 +++++++++++++ mumd/src/audio/transformers.rs | 1 + mumd/src/error.rs | 6 ++++++ mumd/src/main.rs | 17 +++++++++-------- mumd/src/network/tcp.rs | 10 +++++++++- mumd/src/state.rs | 13 +++++++++++++ 8 files changed, 73 insertions(+), 9 deletions(-) (limited to 'mumd/src') diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs index 2e20583..fa22188 100644 --- a/mumd/src/audio.rs +++ b/mumd/src/audio.rs @@ -112,6 +112,16 @@ impl AudioInput { } } +impl Debug for AudioInput { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("AudioInput") + .field("device", &self.device) + .field("channel_receiver", &"receiver") + .finish() + } +} + +#[derive(Debug)] pub struct AudioOutput { device: DefaultAudioOutputDevice, user_volumes: Arc>>, diff --git a/mumd/src/audio/input.rs b/mumd/src/audio/input.rs index a1227e3..2a904d9 100644 --- a/mumd/src/audio/input.rs +++ b/mumd/src/audio/input.rs @@ -1,6 +1,7 @@ use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use cpal::{InputCallbackInfo, Sample, SampleFormat, SampleRate, StreamConfig}; use log::*; +use std::fmt::Debug; use tokio::sync::watch; use crate::audio::SAMPLE_RATE; @@ -177,3 +178,14 @@ impl AudioInputDevice for DefaultAudioInputDevice { self.channels as usize } } + +impl Debug for DefaultAudioInputDevice { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("DefaultAudioInputDevice") + .field("sample_receiver", &self.sample_receiver) + .field("channels", &self.channels) + .field("volume_sender", &self.volume_sender) + .field("stream", &"cpal::Stream") + .finish() + } +} diff --git a/mumd/src/audio/output.rs b/mumd/src/audio/output.rs index a2f6bcc..cdbe336 100644 --- a/mumd/src/audio/output.rs +++ b/mumd/src/audio/output.rs @@ -7,12 +7,14 @@ use cpal::{OutputCallbackInfo, Sample, SampleFormat, SampleRate, StreamConfig}; use log::*; use mumble_protocol::voice::VoicePacketPayload; use std::collections::{HashMap, VecDeque}; +use std::fmt::Debug; use std::ops::AddAssign; use std::sync::{Arc, Mutex}; use tokio::sync::watch; type ClientStreamKey = (VoiceStreamType, u32); +#[derive(Debug)] pub struct ClientStream { buffer_clients: HashMap, opus::Decoder)>, //TODO ring buffer? buffer_effects: VecDeque, @@ -242,3 +244,14 @@ pub fn curry_callback } } } + +impl Debug for DefaultAudioOutputDevice { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("DefaultAudioInputDevice") + .field("client_streams", &self.client_streams) + .field("config", &self.config) + .field("volume_sender", &self.volume_sender) + .field("stream", &"cpal::Stream") + .finish() + } +} diff --git a/mumd/src/audio/transformers.rs b/mumd/src/audio/transformers.rs index 25e28b8..74d751a 100644 --- a/mumd/src/audio/transformers.rs +++ b/mumd/src/audio/transformers.rs @@ -6,6 +6,7 @@ pub trait Transformer { } /// A struct representing a noise gate transform. +#[derive(Debug)] pub struct NoiseGate { alltime_high: f32, open: usize, diff --git a/mumd/src/error.rs b/mumd/src/error.rs index da1bdd3..4277d7f 100644 --- a/mumd/src/error.rs +++ b/mumd/src/error.rs @@ -5,6 +5,7 @@ use tokio::sync::mpsc; pub type ServerSendError = mpsc::error::SendError>; +#[derive(Debug)] pub enum TcpError { NoConnectionInfoReceived, TlsConnectorBuilderError(native_tls::Error), @@ -40,6 +41,7 @@ impl From for TcpError { } } +#[derive(Debug)] pub enum UdpError { NoConnectionInfoReceived, DisconnectBeforeCryptSetup, @@ -53,6 +55,7 @@ impl From for UdpError { } } +#[derive(Debug)] pub enum ClientError { TcpError(TcpError), } @@ -65,6 +68,7 @@ impl fmt::Display for ClientError { } } +#[derive(Debug)] pub enum AudioStream { Input, Output, @@ -79,6 +83,7 @@ impl fmt::Display for AudioStream { } } +#[derive(Debug)] pub enum AudioError { NoDevice(AudioStream), NoConfigs(AudioStream, cpal::SupportedStreamConfigsError), @@ -105,6 +110,7 @@ impl fmt::Display for AudioError { } } +#[derive(Debug)] pub enum StateError { AudioError(AudioError), ConfigError(ConfigError), diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 29ea77f..6b863c1 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -1,18 +1,19 @@ #![warn(elided_lifetimes_in_paths)] #![warn(meta_variable_misuse)] -#![warn(missing_debug_implementations)] //doesn't seem to work +#![warn(missing_debug_implementations)] #![warn(single_use_lifetimes)] +#![warn(unreachable_pub)] #![deny(keyword_idents)] #![deny(macro_use_extern_crate)] #![deny(missing_abi)] -mod audio; -mod client; -mod command; -mod error; -mod network; -mod notifications; -mod state; +pub mod audio; +pub mod client; +pub mod command; +pub mod error; +pub mod network; +pub mod notifications; +pub mod state; use crate::state::State; diff --git a/mumd/src/network/tcp.rs b/mumd/src/network/tcp.rs index a76814c..f68dd31 100644 --- a/mumd/src/network/tcp.rs +++ b/mumd/src/network/tcp.rs @@ -14,6 +14,7 @@ use mumble_protocol::{Clientbound, Serverbound}; use mumlib::command::MumbleEventKind; use std::collections::HashMap; use std::convert::{Into, TryInto}; +use std::fmt::Debug; use std::net::SocketAddr; use std::sync::{Arc, RwLock}; use tokio::net::TcpStream; @@ -57,7 +58,7 @@ pub enum TcpEvent { /// Having two different types might feel a bit confusing. Essentially, a /// callback _registers_ to a [TcpEvent] but _takes_ a [TcpEventData] as /// parameter. -#[derive(Clone)] +#[derive(Clone, Debug)] pub enum TcpEventData<'a> { Connected(Result<&'a msgs::ServerSync, mumlib::Error>), Disconnected(DisconnectedReason), @@ -139,6 +140,13 @@ impl TcpEventQueue { } } +impl Debug for TcpEventQueue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("TcpEventQueue") + .finish() + } +} + pub async fn handle( state: Arc>, mut connection_info_receiver: watch::Receiver>, diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 38d54d3..82810de 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -20,6 +20,7 @@ use mumlib::command::{ChannelTarget, Command, CommandResponse, MessageTarget, Mu use mumlib::config::Config; use mumlib::Error; use std::{ + fmt::Debug, iter, net::{SocketAddr, ToSocketAddrs}, sync::{Arc, RwLock}, @@ -63,6 +64,17 @@ pub enum ExecutionContext { ), } +impl Debug for ExecutionContext { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_tuple(match self { + ExecutionContext::TcpEventCallback(_) => "TcpEventCallback", + ExecutionContext::TcpEventSubscriber(_, _) => "TcpEventSubscriber", + ExecutionContext::Now(_) => "Now", + ExecutionContext::Ping(_, _) => "Ping", + }).finish() + } +} + #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum StatePhase { Disconnected, @@ -70,6 +82,7 @@ pub enum StatePhase { Connected(VoiceStreamType), } +#[derive(Debug)] pub struct State { config: Config, server: Option, -- cgit v1.2.1 From 492efc8b0dd5087991b580787ad75f0d3b57e7e7 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 20:50:04 +0200 Subject: forbid unsafe --- mumd/src/main.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 6b863c1..0db6d35 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -6,6 +6,7 @@ #![deny(keyword_idents)] #![deny(macro_use_extern_crate)] #![deny(missing_abi)] +#![forbid(unsafe_code)] pub mod audio; pub mod client; -- cgit v1.2.1 From e21cbbb8bb35644461aad351458bfbfd3d047954 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 20:56:18 +0200 Subject: add unused_crate_dependencies lint --- mumd/src/main.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 0db6d35..6dc0cf0 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -3,6 +3,7 @@ #![warn(missing_debug_implementations)] #![warn(single_use_lifetimes)] #![warn(unreachable_pub)] +#![warn(unused_crate_dependencies)] #![deny(keyword_idents)] #![deny(macro_use_extern_crate)] #![deny(missing_abi)] -- cgit v1.2.1 From 78d36cd1dc4b9f66baf5a323f5ca24c0ae27d766 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 20:57:19 +0200 Subject: add unused_import_braces lint --- mumd/src/main.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 6dc0cf0..dc10146 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -4,6 +4,7 @@ #![warn(single_use_lifetimes)] #![warn(unreachable_pub)] #![warn(unused_crate_dependencies)] +#![warn(unused_import_braces)] #![deny(keyword_idents)] #![deny(macro_use_extern_crate)] #![deny(missing_abi)] -- cgit v1.2.1 From e799939afee27c47f9d78d987f50d9846b58ea8c Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 20:57:51 +0200 Subject: add unused_lifetimes lint --- mumd/src/main.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index dc10146..536e382 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -5,6 +5,7 @@ #![warn(unreachable_pub)] #![warn(unused_crate_dependencies)] #![warn(unused_import_braces)] +#![warn(unused_lifetimes)] #![deny(keyword_idents)] #![deny(macro_use_extern_crate)] #![deny(missing_abi)] -- cgit v1.2.1 From 817a949cfc3b2a8687d7621eae5fdb49667adac2 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 20:58:59 +0200 Subject: add unused_qualifications lint --- mumd/src/main.rs | 1 + mumd/src/state/user.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 536e382..a53e1a0 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -6,6 +6,7 @@ #![warn(unused_crate_dependencies)] #![warn(unused_import_braces)] #![warn(unused_lifetimes)] +#![warn(unused_qualifications)] #![deny(keyword_idents)] #![deny(macro_use_extern_crate)] #![deny(missing_abi)] diff --git a/mumd/src/state/user.rs b/mumd/src/state/user.rs index 5770bca..0ffde90 100644 --- a/mumd/src/state/user.rs +++ b/mumd/src/state/user.rs @@ -78,7 +78,7 @@ impl User { } } - pub fn apply_user_diff(&mut self, diff: &crate::state::user::UserDiff) { + pub fn apply_user_diff(&mut self, diff: &UserDiff) { if let Some(comment) = diff.comment.clone() { self.comment = Some(comment); } -- cgit v1.2.1 From a331f7867bcf065305c1e5009dc9ee9dd7a17845 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 21:03:59 +0200 Subject: add future_incompatible lint --- mumd/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index a53e1a0..e6a3321 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -7,9 +7,9 @@ #![warn(unused_import_braces)] #![warn(unused_lifetimes)] #![warn(unused_qualifications)] -#![deny(keyword_idents)] #![deny(macro_use_extern_crate)] #![deny(missing_abi)] +#![deny(future_incompatible)] #![forbid(unsafe_code)] pub mod audio; -- cgit v1.2.1 From 96ac62de9f93bbd1530456369ecdb57b177564cb Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sun, 13 Jun 2021 21:21:28 +0200 Subject: add non_ascii_idents lint --- mumd/src/main.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index e6a3321..8d278c0 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -11,6 +11,7 @@ #![deny(missing_abi)] #![deny(future_incompatible)] #![forbid(unsafe_code)] +#![forbid(non_ascii_idents)] pub mod audio; pub mod client; -- cgit v1.2.1 From f24f23faa240053b7ac8f65b69ff8d1ae0ad3ea1 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 14 Jun 2021 13:44:08 +0200 Subject: clippy --- mumd/src/audio/input.rs | 4 ++-- mumd/src/audio/output.rs | 4 ++-- mumd/src/client.rs | 2 +- mumd/src/main.rs | 13 ++++--------- mumd/src/network.rs | 4 ++-- mumd/src/network/tcp.rs | 21 +++++++++++---------- mumd/src/network/udp.rs | 19 ++++++++++--------- mumd/src/state.rs | 23 +++++++++-------------- mumd/src/state/server.rs | 2 +- 9 files changed, 42 insertions(+), 50 deletions(-) (limited to 'mumd/src') diff --git a/mumd/src/audio/input.rs b/mumd/src/audio/input.rs index 2a904d9..88efa62 100644 --- a/mumd/src/audio/input.rs +++ b/mumd/src/audio/input.rs @@ -161,12 +161,12 @@ impl AudioInputDevice for DefaultAudioInputDevice { fn play(&self) -> Result<(), AudioError> { self.stream .play() - .map_err(|e| AudioError::InputPlayError(e)) + .map_err(AudioError::InputPlayError) } fn pause(&self) -> Result<(), AudioError> { self.stream .pause() - .map_err(|e| AudioError::InputPauseError(e)) + .map_err(AudioError::InputPauseError) } fn set_volume(&self, volume: f32) { self.volume_sender.send(volume).unwrap(); diff --git a/mumd/src/audio/output.rs b/mumd/src/audio/output.rs index cdbe336..7487af2 100644 --- a/mumd/src/audio/output.rs +++ b/mumd/src/audio/output.rs @@ -191,13 +191,13 @@ impl AudioOutputDevice for DefaultAudioOutputDevice { fn play(&self) -> Result<(), AudioError> { self.stream .play() - .map_err(|e| AudioError::OutputPlayError(e)) + .map_err(AudioError::OutputPlayError) } fn pause(&self) -> Result<(), AudioError> { self.stream .pause() - .map_err(|e| AudioError::OutputPauseError(e)) + .map_err(AudioError::OutputPauseError) } fn set_volume(&self, volume: f32) { diff --git a/mumd/src/client.rs b/mumd/src/client.rs index 9e8ca18..753583f 100644 --- a/mumd/src/client.rs +++ b/mumd/src/client.rs @@ -33,7 +33,7 @@ pub async fn handle( packet_sender.clone(), packet_receiver, event_queue.clone(), - ).fuse() => r.map_err(|e| ClientError::TcpError(e)), + ).fuse() => r.map_err(ClientError::TcpError), _ = udp::handle( Arc::clone(&state), connection_info_receiver.clone(), diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 8d278c0..6a70586 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -37,9 +37,7 @@ use tokio_util::codec::{FramedRead, FramedWrite, LengthDelimitedCodec}; #[tokio::main] async fn main() { - if std::env::args() - .find(|s| s.as_str() == "--version") - .is_some() + if std::env::args().any(|s| s.as_str() == "--version") { println!("mumd {}", env!("VERSION")); return; @@ -94,12 +92,9 @@ async fn main() { _ = receive_commands(command_sender).fuse() => Ok(()), }; - match run { - Err(e) => { - error!("mumd: {}", e); - std::process::exit(1); - } - _ => {} + if let Err(e) = run { + error!("mumd: {}", e); + std::process::exit(1); } } diff --git a/mumd/src/network.rs b/mumd/src/network.rs index 2b803c0..1066fef 100644 --- a/mumd/src/network.rs +++ b/mumd/src/network.rs @@ -30,8 +30,8 @@ impl ConnectionInfo { #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] pub enum VoiceStreamType { - TCP, - UDP, + Tcp, + Udp, } async fn run_until( diff --git a/mumd/src/network/tcp.rs b/mumd/src/network/tcp.rs index f68dd31..0fdc4c5 100644 --- a/mumd/src/network/tcp.rs +++ b/mumd/src/network/tcp.rs @@ -75,7 +75,7 @@ impl From<&TcpEventData<'_>> for TcpEvent { } } -#[derive(Clone)] +#[derive(Clone, Default)] pub struct TcpEventQueue { callbacks: Arc>>>, subscribers: Arc>>>, @@ -156,13 +156,14 @@ pub async fn handle( event_queue: TcpEventQueue, ) -> Result<(), TcpError> { loop { - let connection_info = 'data: loop { - while connection_info_receiver.changed().await.is_ok() { + let connection_info = loop { + if connection_info_receiver.changed().await.is_ok() { if let Some(data) = connection_info_receiver.borrow().clone() { - break 'data data; + break data; } + } else { + return Err(TcpError::NoConnectionInfoReceived); } - return Err(TcpError::NoConnectionInfoReceived); }; let connect_result = connect( connection_info.socket_addr, @@ -250,12 +251,12 @@ async fn connect( builder.danger_accept_invalid_certs(accept_invalid_cert); let connector: TlsConnector = builder .build() - .map_err(|e| TcpError::TlsConnectorBuilderError(e))? + .map_err(TcpError::TlsConnectorBuilderError)? .into(); let tls_stream = connector .connect(&server_host, stream) .await - .map_err(|e| TcpError::TlsConnectError(e))?; + .map_err(TcpError::TlsConnectError)?; debug!("TLS connected"); // Wrap the TLS stream with Mumble's client-side control-channel codec @@ -312,13 +313,13 @@ async fn send_voice( inner_phase_watcher.changed().await.unwrap(); if matches!( *inner_phase_watcher.borrow(), - StatePhase::Connected(VoiceStreamType::TCP) + StatePhase::Connected(VoiceStreamType::Tcp) ) { break; } } run_until( - |phase| !matches!(phase, StatePhase::Connected(VoiceStreamType::TCP)), + |phase| !matches!(phase, StatePhase::Connected(VoiceStreamType::Tcp)), async { loop { packet_sender.send( @@ -473,7 +474,7 @@ async fn listen( .. } => { state.read().unwrap().audio_output().decode_packet_payload( - VoiceStreamType::TCP, + VoiceStreamType::Tcp, session_id, payload, ); diff --git a/mumd/src/network/udp.rs b/mumd/src/network/udp.rs index 95dcf33..0f78638 100644 --- a/mumd/src/network/udp.rs +++ b/mumd/src/network/udp.rs @@ -37,13 +37,14 @@ pub async fn handle( let receiver = state.read().unwrap().audio_input().receiver(); loop { - let connection_info = 'data: loop { - while connection_info_receiver.changed().await.is_ok() { + let connection_info = loop { + if connection_info_receiver.changed().await.is_ok() { if let Some(data) = connection_info_receiver.borrow().clone() { - break 'data data; + break data; } + } else { + return Err(UdpError::NoConnectionInfoReceived); } - return Err(UdpError::NoConnectionInfoReceived); }; let (sink, source) = connect(&mut crypt_state_receiver).await?; @@ -136,7 +137,7 @@ async fn listen( state .read() .unwrap() - .broadcast_phase(StatePhase::Connected(VoiceStreamType::UDP)); + .broadcast_phase(StatePhase::Connected(VoiceStreamType::Udp)); last_ping_recv.store(timestamp, Ordering::Relaxed); } VoicePacket::Audio { @@ -147,7 +148,7 @@ async fn listen( .. } => { state.read().unwrap().audio_output().decode_packet_payload( - VoiceStreamType::UDP, + VoiceStreamType::Udp, session_id, payload, ); @@ -173,7 +174,7 @@ async fn send_pings( state .read() .unwrap() - .broadcast_phase(StatePhase::Connected(VoiceStreamType::TCP)); + .broadcast_phase(StatePhase::Connected(VoiceStreamType::Tcp)); } match sink .lock() @@ -208,13 +209,13 @@ async fn send_voice( inner_phase_watcher.changed().await.unwrap(); if matches!( *inner_phase_watcher.borrow(), - StatePhase::Connected(VoiceStreamType::UDP) + StatePhase::Connected(VoiceStreamType::Udp) ) { break; } } run_until( - |phase| !matches!(phase, StatePhase::Connected(VoiceStreamType::UDP)), + |phase| !matches!(phase, StatePhase::Connected(VoiceStreamType::Udp)), async { let mut receiver = receiver.lock().await; loop { diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 82810de..a1344a1 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -43,18 +43,13 @@ macro_rules! now { type Responses = Box>>>; +type TcpEventCallback = Box) -> Responses>; +type TcpEventSubscriberCallback = Box,&mut mpsc::UnboundedSender>>,) -> bool>; + //TODO give me a better name pub enum ExecutionContext { - TcpEventCallback(Vec<(TcpEvent, Box) -> Responses>)>), - TcpEventSubscriber( - TcpEvent, - Box< - dyn FnMut( - TcpEventData<'_>, - &mut mpsc::UnboundedSender>>, - ) -> bool, - >, - ), + TcpEventCallback(Vec<(TcpEvent, TcpEventCallback)>), + TcpEventSubscriber(TcpEvent, TcpEventSubscriberCallback), Now(Box Responses>), Ping( Box mumlib::error::Result>, @@ -103,9 +98,9 @@ impl State { config.audio.input_volume.unwrap_or(1.0), phase_watcher.1.clone(), ) - .map_err(|e| StateError::AudioError(e))?; + .map_err(StateError::AudioError)?; let audio_output = AudioOutput::new(config.audio.output_volume.unwrap_or(1.0)) - .map_err(|e| StateError::AudioError(e))?; + .map_err(StateError::AudioError)?; let mut state = Self { config, server: None, @@ -321,7 +316,7 @@ impl State { } pub fn initialized(&self) { - self.broadcast_phase(StatePhase::Connected(VoiceStreamType::TCP)); + self.broadcast_phase(StatePhase::Connected(VoiceStreamType::Tcp)); self.audio_output .play_effect(NotificationEvents::ServerConnect); } @@ -786,7 +781,7 @@ pub fn handle_command( .unwrap() .users() .iter() - .find(|(_, user)| user.name() == &name) + .find(|(_, user)| user.name() == name) .map(|(e, _)| *e); let id = match id { diff --git a/mumd/src/state/server.rs b/mumd/src/state/server.rs index 4abde49..5d49457 100644 --- a/mumd/src/state/server.rs +++ b/mumd/src/state/server.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use std::collections::hash_map::Entry; use std::collections::HashMap; -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct Server { channels: HashMap, users: HashMap, -- cgit v1.2.1 From 4b263196d3a41c99f7dc1acf659a9f9083163d5e Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sat, 19 Jun 2021 17:51:04 +0200 Subject: feedback --- mumd/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'mumd/src') diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 6a70586..479c568 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -37,8 +37,7 @@ use tokio_util::codec::{FramedRead, FramedWrite, LengthDelimitedCodec}; #[tokio::main] async fn main() { - if std::env::args().any(|s| s.as_str() == "--version") - { + if std::env::args().any(|s| s.as_str() == "--version") { println!("mumd {}", env!("VERSION")); return; } -- cgit v1.2.1 From 9aca7a8c930b179b6ae539234296f529928a3f3a Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sat, 19 Jun 2021 19:13:11 +0200 Subject: add line breaks --- mumd/src/state.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'mumd/src') diff --git a/mumd/src/state.rs b/mumd/src/state.rs index a1344a1..1992884 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -44,7 +44,12 @@ macro_rules! now { type Responses = Box>>>; type TcpEventCallback = Box) -> Responses>; -type TcpEventSubscriberCallback = Box,&mut mpsc::UnboundedSender>>,) -> bool>; +type TcpEventSubscriberCallback = Box< + dyn FnMut( + TcpEventData<'_>, + &mut mpsc::UnboundedSender>>, + ) -> bool +>; //TODO give me a better name pub enum ExecutionContext { -- cgit v1.2.1