mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
chore: enforce some more clippy lints
pumpkin contributors will love me :cap:
This commit is contained in:
@@ -42,7 +42,7 @@ impl Command {
|
||||
///
|
||||
/// Registers `handler` so that it is called whenever this command is invoked.
|
||||
/// Returns `self` to allow builder-style chaining.
|
||||
pub fn execute<H: CommandHandler + Send + Sync + 'static>(self, handler: H) -> Command {
|
||||
pub fn execute<H: CommandHandler + Send + Sync + 'static>(self, handler: H) -> Self {
|
||||
let id = NEXT_COMMAND_ID.fetch_add(1, Ordering::Relaxed);
|
||||
|
||||
COMMAND_HANDLERS
|
||||
@@ -62,7 +62,7 @@ impl CommandNode {
|
||||
/// Registers `handler` so that it is called when this specific node (subcommand
|
||||
/// or argument branch) is the final node matched during command dispatch.
|
||||
/// Returns `self` to allow builder-style chaining.
|
||||
pub fn execute<H: CommandHandler + Send + Sync + 'static>(self, handler: H) -> CommandNode {
|
||||
pub fn execute<H: CommandHandler + Send + Sync + 'static>(self, handler: H) -> Self {
|
||||
let id = NEXT_COMMAND_ID.fetch_add(1, Ordering::Relaxed);
|
||||
|
||||
COMMAND_HANDLERS
|
||||
|
||||
@@ -181,6 +181,7 @@ pub enum FormResponse {
|
||||
}
|
||||
|
||||
impl FormResponse {
|
||||
#[must_use]
|
||||
pub fn parse(data: Option<String>) -> Self {
|
||||
match data {
|
||||
None => Self::Closed,
|
||||
|
||||
@@ -136,13 +136,14 @@ impl wit::Guest for Component {
|
||||
args: command::ConsumedArgs,
|
||||
) -> Result<i32, command::CommandError> {
|
||||
let handlers = COMMAND_HANDLERS.lock().unwrap();
|
||||
if let Some(handler) = handlers.get(&command_id) {
|
||||
handler.handle(sender, server, args)
|
||||
} else {
|
||||
Err(command::CommandError::CommandFailed(TextComponent::text(
|
||||
&format!("no handler registered for command id {command_id}"),
|
||||
)))
|
||||
}
|
||||
handlers.get(&command_id).map_or_else(
|
||||
|| {
|
||||
Err(command::CommandError::CommandFailed(TextComponent::text(
|
||||
&format!("no handler registered for command id {command_id}"),
|
||||
)))
|
||||
},
|
||||
|handler| handler.handle(sender, server, args),
|
||||
)
|
||||
}
|
||||
|
||||
/// WIT entry point — dispatches a scheduled task invocation to the registered handler for `handler_id`.
|
||||
|
||||
@@ -13,7 +13,7 @@ pub(crate) struct WitSubscriber {
|
||||
|
||||
impl WitSubscriber {
|
||||
/// Creates a new `WitSubscriber` with the span ID counter starting at `1`.
|
||||
pub fn new() -> Self {
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
next_id: AtomicU64::new(1),
|
||||
}
|
||||
@@ -69,13 +69,13 @@ pub enum LogLevel {
|
||||
|
||||
impl LogLevel {
|
||||
/// Converts this level to the WIT-generated `Level` type expected by the host.
|
||||
fn to_wit(self) -> wit::pumpkin::plugin::logging::Level {
|
||||
const fn to_wit(self) -> wit::pumpkin::plugin::logging::Level {
|
||||
match self {
|
||||
LogLevel::Trace => wit::pumpkin::plugin::logging::Level::Trace,
|
||||
LogLevel::Debug => wit::pumpkin::plugin::logging::Level::Debug,
|
||||
LogLevel::Info => wit::pumpkin::plugin::logging::Level::Info,
|
||||
LogLevel::Warn => wit::pumpkin::plugin::logging::Level::Warn,
|
||||
LogLevel::Error => wit::pumpkin::plugin::logging::Level::Error,
|
||||
Self::Trace => wit::pumpkin::plugin::logging::Level::Trace,
|
||||
Self::Debug => wit::pumpkin::plugin::logging::Level::Debug,
|
||||
Self::Info => wit::pumpkin::plugin::logging::Level::Info,
|
||||
Self::Warn => wit::pumpkin::plugin::logging::Level::Warn,
|
||||
Self::Error => wit::pumpkin::plugin::logging::Level::Error,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,14 +95,14 @@ impl SchedulerExt for crate::Context {
|
||||
impl SchedulerExt for crate::Server {
|
||||
fn schedule_delayed_task<F>(&self, delay_ticks: u64, handler: F) -> u32
|
||||
where
|
||||
F: FnMut(Server) + Send + 'static,
|
||||
F: FnMut(Self) + Send + 'static,
|
||||
{
|
||||
schedule_delayed_task(delay_ticks, handler)
|
||||
}
|
||||
|
||||
fn schedule_repeating_task<F>(&self, delay_ticks: u64, period_ticks: u64, handler: F) -> u32
|
||||
where
|
||||
F: FnMut(Server) + Send + 'static,
|
||||
F: FnMut(Self) + Send + 'static,
|
||||
{
|
||||
schedule_repeating_task(delay_ticks, period_ticks, handler)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user