Files
soulseek-rs-modded/soulseek-rs-lib/src/message/handlers.rs
T
michel e72c8a5c07 style: crank clippy to pedantic+nursery and fix all lints
Enable the full clippy all + pedantic + nursery groups as workspace warnings,
with a small documented allow-list for the pedantic/nursery lints this project
intentionally does not follow (rustdoc-style requirements, deliberate numeric
casts in the protocol/UI layers, and a few noisy nursery lints). Also enable
the rust unused_lifetimes and unsafe_op_in_unsafe_fn lints.

Fixed every resulting warning (527 -> 0) mechanically per clippy's suggestions:
inline format args, const fns, item ordering, let-else, redundant clones,
map_or, cast_lossless, Eq derives, associated-fn conversions for methods that
never used self, and removing unnecessary Result wrappers whose call sites could
never propagate an error. No runtime behavior changed; cargo fmt applied.

cargo clippy --workspace --all-targets: 0 warnings. All tests pass.
2026-07-19 00:09:17 +02:00

43 lines
952 B
Rust

use std::collections::HashMap;
use crate::message::Message;
use std::sync::mpsc::Sender;
pub trait MessageHandler<Op>: Send {
fn get_code(&self) -> u8;
fn handle(&self, message: &mut Message, sender: Sender<Op>);
}
pub struct Handlers<Op> {
handlers: HashMap<u8, Box<dyn MessageHandler<Op> + Send>>,
}
impl<Op> Default for Handlers<Op> {
fn default() -> Self {
Self::new()
}
}
impl<Op> Handlers<Op> {
#[must_use]
pub fn new() -> Self {
Self {
handlers: HashMap::new(),
}
}
pub fn register_handler<H>(&mut self, handler: H) -> &mut Self
where
H: 'static + MessageHandler<Op> + Send + Sync,
{
self.handlers.insert(handler.get_code(), Box::new(handler));
self
}
#[must_use]
pub fn get_handler(
&self,
code: u8,
) -> Option<&(dyn MessageHandler<Op> + Send)> {
self.handlers.get(&code).map(|v| &**v)
}
}