Fix clippy warnings (#236)

This commit is contained in:
Gnome!
2024-04-02 08:57:47 +01:00
committed by GitHub
parent 1d5b25965b
commit 5bbe80f20c
28 changed files with 35 additions and 63 deletions

View File

@@ -390,8 +390,8 @@ impl Config {
// Test only attributes // Test only attributes
#[cfg(all(test, feature = "driver"))] #[cfg(all(test, feature = "driver"))]
#[allow(missing_docs)]
impl Config { impl Config {
#![allow(missing_docs)]
#[must_use] #[must_use]
pub fn tick_style(mut self, tick_style: TickStyle) -> Self { pub fn tick_style(mut self, tick_style: TickStyle) -> Self {
self.tick_style = tick_style; self.tick_style = tick_style;

View File

@@ -14,6 +14,7 @@ use crate::{
tracks::{Track, TrackHandle}, tracks::{Track, TrackHandle},
}; };
#[must_use]
pub fn track_context(t: Track) -> (TrackHandle, TrackContext) { pub fn track_context(t: Track) -> (TrackHandle, TrackContext) {
t.into_context() t.into_context()
} }

View File

@@ -249,6 +249,7 @@ impl CryptoState {
} }
/// Returns the underlying (stateless) type of the active crypto mode. /// Returns the underlying (stateless) type of the active crypto mode.
#[must_use]
pub fn kind(self) -> CryptoMode { pub fn kind(self) -> CryptoMode {
CryptoMode::from(self) CryptoMode::from(self)
} }

View File

@@ -1,5 +1,3 @@
use std::num::NonZeroUsize;
use super::*; use super::*;
/// Configuration for how a [`Scheduler`] handles tasks. /// Configuration for how a [`Scheduler`] handles tasks.

View File

@@ -1,6 +1,5 @@
use std::{collections::HashMap, sync::Arc, time::Duration}; use std::{collections::HashMap, time::Duration};
use flume::{Receiver, Sender};
use nohash_hasher::{BuildNoHashHasher, IntMap}; use nohash_hasher::{BuildNoHashHasher, IntMap};
use tokio::time::{Instant as TokInstant, Interval}; use tokio::time::{Instant as TokInstant, Interval};
use tracing::info; use tracing::info;

View File

@@ -1,10 +1,7 @@
use std::{ use std::time::{Duration, Instant};
sync::Arc,
time::{Duration, Instant},
};
use discortp::rtp::{MutableRtpPacket, RtpPacket}; use discortp::rtp::{MutableRtpPacket, RtpPacket};
use flume::{Receiver, SendError, Sender, TryRecvError}; use flume::{SendError, TryRecvError};
use tokio::time::Instant as TokInstant; use tokio::time::Instant as TokInstant;
use crate::{ use crate::{
@@ -86,12 +83,14 @@ impl Worker {
/// Return whether this thread has enough room (task count, spare cycles) /// Return whether this thread has enough room (task count, spare cycles)
/// for the given task. /// for the given task.
#[inline] #[inline]
#[must_use]
pub fn can_schedule(&self, task: &ParkedMixer, avoid: Option<WorkerId>) -> bool { pub fn can_schedule(&self, task: &ParkedMixer, avoid: Option<WorkerId>) -> bool {
avoid.map_or(true, |id| !self.has_id(id)) avoid.map_or(true, |id| !self.has_id(id))
&& self.stats.has_room(&self.config.strategy, task) && self.stats.has_room(&self.config.strategy, task)
} }
#[inline] #[inline]
#[must_use]
pub fn stats(&self) -> Arc<LiveStatBlock> { pub fn stats(&self) -> Arc<LiveStatBlock> {
self.stats.clone() self.stats.clone()
} }
@@ -108,6 +107,7 @@ impl Worker {
self.tx.send((id, task)) self.tx.send((id, task))
} }
#[must_use]
pub fn has_id(&self, id: WorkerId) -> bool { pub fn has_id(&self, id: WorkerId) -> bool {
self.id == id self.id == id
} }

View File

@@ -38,6 +38,7 @@ impl<T> IsEnabled for ResId<T> {}
#[allow(missing_docs)] #[allow(missing_docs)]
impl<T: Copy> ResId<T> { impl<T: Copy> ResId<T> {
#[must_use]
pub fn new() -> Self { pub fn new() -> Self {
Self::default() Self::default()
} }
@@ -49,6 +50,7 @@ impl<T: Copy> ResId<T> {
} }
#[cfg(any(test, feature = "internals"))] #[cfg(any(test, feature = "internals"))]
#[must_use]
pub fn get(self) -> u64 { pub fn get(self) -> u64 {
self.0 self.0
} }
@@ -88,6 +90,7 @@ pub struct ParkedMixer {
#[allow(missing_docs)] #[allow(missing_docs)]
impl ParkedMixer { impl ParkedMixer {
/// Create a new `Mixer` in a parked state. /// Create a new `Mixer` in a parked state.
#[must_use]
pub fn new(mix_rx: Receiver<MixerMessage>, interconnect: Interconnect, config: Config) -> Self { pub fn new(mix_rx: Receiver<MixerMessage>, interconnect: Interconnect, config: Config) -> Self {
Self { Self {
mixer: Box::new(Mixer::new(mix_rx, Handle::current(), interconnect, config)), mixer: Box::new(Mixer::new(mix_rx, Handle::current(), interconnect, config)),

View File

@@ -25,8 +25,7 @@ pub enum Error {
IllegalVoicePacket, IllegalVoicePacket,
InterconnectFailure(Recipient), InterconnectFailure(Recipient),
Io(IoError), Io(IoError),
Opus(OpusError), Other,
Ws(WsError),
} }
impl Error { impl Error {
@@ -66,8 +65,8 @@ impl From<IoError> for Error {
} }
impl From<OpusError> for Error { impl From<OpusError> for Error {
fn from(e: OpusError) -> Error { fn from(_: OpusError) -> Error {
Error::Opus(e) Error::Other
} }
} }
@@ -97,7 +96,7 @@ impl From<SendError<UdpRxMessage>> for Error {
} }
impl From<WsError> for Error { impl From<WsError> for Error {
fn from(e: WsError) -> Error { fn from(_: WsError) -> Error {
Error::Ws(e) Error::Other
} }
} }

View File

@@ -2,6 +2,7 @@
use crate::{driver::tasks::mixer::InternalTrack, tracks::TrackHandle}; use crate::{driver::tasks::mixer::InternalTrack, tracks::TrackHandle};
#[allow(dead_code)] // We don't read because all we are doing is dropping.
pub enum DisposalMessage { pub enum DisposalMessage {
Track(Box<InternalTrack>), Track(Box<InternalTrack>),
Handle(TrackHandle), Handle(TrackHandle),

View File

@@ -40,6 +40,7 @@ pub enum MixerMessage {
} }
impl MixerMessage { impl MixerMessage {
#[must_use]
pub fn is_mixer_maybe_live(&self) -> bool { pub fn is_mixer_maybe_live(&self) -> bool {
matches!( matches!(
self, self,

View File

@@ -64,7 +64,6 @@ pub struct Mixer {
pub bitrate: Bitrate, pub bitrate: Bitrate,
pub config: Arc<Config>, pub config: Arc<Config>,
pub conn_active: Option<MixerConnection>, pub conn_active: Option<MixerConnection>,
pub content_prep_sequence: u64,
pub deadline: Instant, pub deadline: Instant,
pub disposer: DisposalThread, pub disposer: DisposalThread,
pub encoder: OpusEncoder, pub encoder: OpusEncoder,
@@ -103,6 +102,7 @@ fn new_encoder(bitrate: Bitrate, mix_mode: MixMode) -> Result<OpusEncoder> {
} }
impl Mixer { impl Mixer {
#[must_use]
pub fn new( pub fn new(
mix_rx: Receiver<MixerMessage>, mix_rx: Receiver<MixerMessage>,
async_handle: Handle, async_handle: Handle,
@@ -151,7 +151,6 @@ impl Mixer {
bitrate, bitrate,
config, config,
conn_active: None, conn_active: None,
content_prep_sequence: 0,
deadline, deadline,
disposer, disposer,
encoder, encoder,

View File

@@ -23,6 +23,7 @@ impl InputState {
} }
} }
#[must_use]
pub fn ready_state(&self) -> ReadyState { pub fn ready_state(&self) -> ReadyState {
match self { match self {
Self::NotReady(_) => ReadyState::Uninitialised, Self::NotReady(_) => ReadyState::Uninitialised,

View File

@@ -1,6 +1,5 @@
use super::*; use super::*;
use bytes::Bytes; use bytes::Bytes;
use discortp::rtp::RtpPacket;
use std::collections::VecDeque; use std::collections::VecDeque;
use tracing::trace; use tracing::trace;

View File

@@ -3,11 +3,9 @@ use crate::{
constants::*, constants::*,
driver::{ driver::{
tasks::error::{Error, Result}, tasks::error::{Error, Result},
CryptoMode,
DecodeMode, DecodeMode,
}, },
events::context_data::{RtpData, VoiceData}, events::context_data::{RtpData, VoiceData},
Config,
}; };
use audiopus::{ use audiopus::{
coder::Decoder as OpusDecoder, coder::Decoder as OpusDecoder,
@@ -15,13 +13,7 @@ use audiopus::{
packet::Packet as OpusPacket, packet::Packet as OpusPacket,
Channels, Channels,
}; };
use discortp::{ use discortp::{rtp::RtpExtensionPacket, Packet, PacketSize};
rtp::{RtpExtensionPacket, RtpPacket},
Packet,
PacketSize,
};
use std::{convert::TryInto, time::Duration};
use tokio::time::Instant;
use tracing::{error, warn}; use tracing::{error, warn};
#[derive(Debug)] #[derive(Debug)]

View File

@@ -12,7 +12,7 @@ use crate::{
tracks::LoopState, tracks::LoopState,
}; };
use crypto_secretbox::{KeyInit, XSalsa20Poly1305 as Cipher}; use crypto_secretbox::{KeyInit, XSalsa20Poly1305 as Cipher};
use flume::{Receiver, Sender}; use flume::Receiver;
use std::{io::Cursor, net::UdpSocket, sync::Arc}; use std::{io::Cursor, net::UdpSocket, sync::Arc};
use tokio::runtime::Handle; use tokio::runtime::Handle;
@@ -38,6 +38,7 @@ pub type Listeners = (Receiver<CoreMessage>, Receiver<EventMessage>);
pub type DummyMixer = (Mixer, Listeners); pub type DummyMixer = (Mixer, Listeners);
impl Mixer { impl Mixer {
#[must_use]
pub fn mock(handle: Handle, softclip: bool) -> DummyMixer { pub fn mock(handle: Handle, softclip: bool) -> DummyMixer {
let (mix_tx, mix_rx) = flume::unbounded(); let (mix_tx, mix_rx) = flume::unbounded();
let (core_tx, core_rx) = flume::unbounded(); let (core_tx, core_rx) = flume::unbounded();
@@ -88,6 +89,7 @@ impl Mixer {
return (out, (core_rx, event_rx)); return (out, (core_rx, event_rx));
} }
#[must_use]
pub fn test_with_float(num_tracks: usize, handle: Handle, softclip: bool) -> DummyMixer { pub fn test_with_float(num_tracks: usize, handle: Handle, softclip: bool) -> DummyMixer {
let mut out = Self::mock(handle, softclip); let mut out = Self::mock(handle, softclip);
@@ -106,6 +108,7 @@ impl Mixer {
out out
} }
#[must_use]
pub fn test_with_float_unending(handle: Handle, softclip: bool) -> (DummyMixer, TrackHandle) { pub fn test_with_float_unending(handle: Handle, softclip: bool) -> (DummyMixer, TrackHandle) {
let mut out = Self::mock(handle, softclip); let mut out = Self::mock(handle, softclip);
@@ -125,6 +128,7 @@ impl Mixer {
(out, handle) (out, handle)
} }
#[must_use]
pub fn test_with_float_drop(num_tracks: usize, handle: Handle) -> DummyMixer { pub fn test_with_float_drop(num_tracks: usize, handle: Handle) -> DummyMixer {
let mut out = Self::mock(handle, true); let mut out = Self::mock(handle, true);
@@ -142,6 +146,7 @@ impl Mixer {
out out
} }
#[must_use]
pub fn test_with_opus(handle: &Handle) -> DummyMixer { pub fn test_with_opus(handle: &Handle) -> DummyMixer {
// should add a single opus-based track. // should add a single opus-based track.
// make this fully loaded to prevent any perf cost there. // make this fully loaded to prevent any perf cost there.

View File

@@ -1,5 +1,5 @@
use super::*; use super::*;
use std::{cmp::Ordering, time::Duration}; use std::cmp::Ordering;
/// Internal representation of an event, as handled by the audio context. /// Internal representation of an event, as handled by the audio context.
pub struct EventData { pub struct EventData {

View File

@@ -3,10 +3,7 @@ use crate::{
constants::*, constants::*,
tracks::{ReadyState, TrackHandle, TrackState}, tracks::{ReadyState, TrackHandle, TrackState},
}; };
use std::{ use std::collections::{BinaryHeap, HashMap};
collections::{BinaryHeap, HashMap},
time::Duration,
};
use tracing::info; use tracing::info;
#[derive(Debug, Default)] #[derive(Debug, Default)]

View File

@@ -19,7 +19,6 @@ use audiopus::{
}; };
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::{ use std::{
convert::TryInto,
io::{ io::{
Cursor, Cursor,
Error as IoError, Error as IoError,

View File

@@ -12,7 +12,6 @@ use symphonia::core::{
meta::{Metadata as SymphMetadata, MetadataBuilder, MetadataLog, StandardTagKey, Tag, Value}, meta::{Metadata as SymphMetadata, MetadataBuilder, MetadataLog, StandardTagKey, Tag, Value},
probe::{Descriptor, Instantiate, QueryDescriptor}, probe::{Descriptor, Instantiate, QueryDescriptor},
sample::SampleFormat, sample::SampleFormat,
units::TimeStamp,
}; };
impl QueryDescriptor for DcaReader { impl QueryDescriptor for DcaReader {

View File

@@ -7,7 +7,6 @@ use symphonia::core::{
io::{MediaSource, MediaSourceStream, ReadBytes, SeekBuffered}, io::{MediaSource, MediaSourceStream, ReadBytes, SeekBuffered},
meta::{Metadata as SymphMetadata, MetadataLog}, meta::{Metadata as SymphMetadata, MetadataLog},
probe::{Descriptor, Instantiate, QueryDescriptor}, probe::{Descriptor, Instantiate, QueryDescriptor},
units::TimeStamp,
}; };
impl QueryDescriptor for RawReader { impl QueryDescriptor for RawReader {

View File

@@ -232,8 +232,6 @@ impl From<HttpRequest> for Input {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use reqwest::Client;
use super::*; use super::*;
use crate::{ use crate::{
constants::test_data::{HTTP_OPUS_TARGET, HTTP_TARGET, HTTP_WEBM_TARGET}, constants::test_data::{HTTP_OPUS_TARGET, HTTP_TARGET, HTTP_WEBM_TARGET},

View File

@@ -225,8 +225,6 @@ impl Compose for YoutubeDl {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use reqwest::Client;
use super::*; use super::*;
use crate::constants::test_data::*; use crate::constants::test_data::*;
use crate::input::input_tests::*; use crate::input::input_tests::*;

View File

@@ -9,7 +9,6 @@ use crate::{
use core::{ use core::{
convert, convert,
future::Future, future::Future,
marker::Unpin,
pin::Pin, pin::Pin,
task::{Context, Poll}, task::{Context, Poll},
time::Duration, time::Duration,

View File

@@ -77,6 +77,7 @@
clippy::missing_errors_doc, clippy::missing_errors_doc,
clippy::missing_panics_doc, clippy::missing_panics_doc,
clippy::doc_link_with_quotes, clippy::doc_link_with_quotes,
clippy::doc_markdown,
)] )]
mod config; mod config;

View File

@@ -1,10 +1,7 @@
use super::*; use super::*;
use crate::events::EventData; use crate::events::EventData;
use flume::Sender; use flume::Sender;
use std::{ use std::fmt::{Debug, Formatter, Result as FmtResult};
fmt::{Debug, Formatter, Result as FmtResult},
time::Duration,
};
/// A request from external code using a [`TrackHandle`] to modify /// A request from external code using a [`TrackHandle`] to modify
/// or act upon an [`Track`] object. /// or act upon an [`Track`] object.

View File

@@ -1,10 +1,9 @@
use super::*; use super::*;
use crate::events::{Event, EventData, EventHandler}; use crate::events::{Event, EventData, EventHandler};
use flume::{Receiver, Sender}; use flume::{Receiver, Sender};
use std::{fmt, sync::Arc, time::Duration}; use std::{fmt, sync::Arc};
use tokio::sync::RwLock; use tokio::sync::RwLock;
use typemap_rev::TypeMap; use typemap_rev::TypeMap;
use uuid::Uuid;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
/// Handle for safe control of a [`Track`] from other threads, outside /// Handle for safe control of a [`Track`] from other threads, outside
@@ -264,13 +263,7 @@ impl<T> TrackCallback<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::{ use crate::{constants::test_data::FILE_WAV_TARGET, driver::Driver, input::File, Config};
constants::test_data::FILE_WAV_TARGET,
driver::Driver,
input::File,
tracks::Track,
Config,
};
#[tokio::test] #[tokio::test]
#[ntest::timeout(10_000)] #[ntest::timeout(10_000)]

View File

@@ -40,13 +40,7 @@ impl TrackState {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::{ use crate::{constants::test_data::YTDL_TARGET, driver::Driver, input::YoutubeDl, Config};
constants::test_data::YTDL_TARGET,
driver::Driver,
input::YoutubeDl,
tracks::Track,
Config,
};
use reqwest::Client; use reqwest::Client;
#[tokio::test] #[tokio::test]

View File

@@ -1,6 +1,5 @@
use super::*; use super::*;
use crate::input::Metadata; use crate::input::Metadata;
use std::time::Duration;
/// Live track and input state exposed during [`TrackHandle::action`]. /// Live track and input state exposed during [`TrackHandle::action`].
/// ///