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.
41 lines
963 B
Rust
41 lines
963 B
Rust
use crate::message::{Message, handlers::Handlers};
|
|
use std::sync::mpsc::Sender;
|
|
|
|
use crate::warn;
|
|
|
|
pub struct MessageDispatcher<Op> {
|
|
owner_name: String,
|
|
sender: Sender<Op>,
|
|
handlers: Handlers<Op>,
|
|
}
|
|
|
|
impl<Op> MessageDispatcher<Op> {
|
|
#[must_use]
|
|
pub const fn new(
|
|
owner_name: String,
|
|
sender: Sender<Op>,
|
|
handlers: Handlers<Op>,
|
|
) -> Self {
|
|
Self {
|
|
owner_name,
|
|
sender,
|
|
handlers,
|
|
}
|
|
}
|
|
|
|
pub fn dispatch(&self, message: &mut Message) {
|
|
let code = message.get_message_code();
|
|
|
|
if let Some(handler) = self.handlers.get_handler(code) {
|
|
message.set_pointer(8);
|
|
handler.handle(message, self.sender.clone());
|
|
} else {
|
|
warn!(
|
|
"[{}:dispatcher] No handler found for message code: {}",
|
|
self.owner_name,
|
|
message.get_message_code()
|
|
);
|
|
}
|
|
}
|
|
}
|