From 2e904225611b66fa72b082e4f5e188b55b333fcd Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 17 Apr 2022 15:57:28 -0500 Subject: Fix clippy issues and add a couple tests to dispatcher --- azalea-brigadier/src/tree.rs | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'azalea-brigadier/src/tree.rs') diff --git a/azalea-brigadier/src/tree.rs b/azalea-brigadier/src/tree.rs index c81c599f..5c33a879 100644 --- a/azalea-brigadier/src/tree.rs +++ b/azalea-brigadier/src/tree.rs @@ -11,15 +11,7 @@ use crate::{ string_range::StringRange, string_reader::StringReader, }; -use std::{ - any::Any, - cell::RefCell, - collections::{BTreeMap, HashMap}, - fmt::Debug, - hash::Hash, - ptr, - rc::Rc, -}; +use std::{any::Any, cell::RefCell, collections::BTreeMap, fmt::Debug, hash::Hash, ptr, rc::Rc}; /// An ArgumentBuilder that has been built. #[derive(Clone)] @@ -67,7 +59,7 @@ impl CommandNode { pub fn get_relevant_nodes(&self, input: &mut StringReader) -> Vec>>> { let literals = self.literals(); - if literals.len() > 0 { + if !literals.is_empty() { let cursor = input.cursor(); while input.can_read() && input.peek() != ' ' { input.skip(); @@ -83,18 +75,10 @@ impl CommandNode { if let Some(literal) = literal { return vec![literal.clone()]; } else { - return self - .arguments() - .values() - .map(|argument| argument.clone()) - .collect(); + return self.arguments().values().cloned().collect(); } } else { - return self - .arguments() - .values() - .map(|argument| argument.clone()) - .collect(); + self.arguments().values().cloned().collect() } } @@ -147,7 +131,7 @@ impl CommandNode { .expect("Couldn't get result for some reason"); let parsed = ParsedArgument { range: StringRange::between(start, reader.cursor()), - result: result, + result, }; context_builder.with_argument(&argument.name, parsed.clone()); @@ -175,7 +159,7 @@ impl CommandNode { fn parse(&self, reader: &mut StringReader) -> Option { match self.value { - ArgumentBuilderType::Argument(ref argument) => { + ArgumentBuilderType::Argument(_) => { panic!("Can't parse argument.") } ArgumentBuilderType::Literal(ref literal) => { @@ -252,7 +236,9 @@ impl PartialEq for CommandNode { return false; } if let Some(selfexecutes) = &self.command { + // idk how to do this better since we can't compare `dyn Fn`s if let Some(otherexecutes) = &other.command { + #[allow(clippy::vtable_address_comparisons)] if !Rc::ptr_eq(selfexecutes, otherexecutes) { return false; } @@ -260,6 +246,9 @@ impl PartialEq for CommandNode { return false; } } + else if other.command.is_some() { + return false; + } true } } -- cgit v1.2.3