Skip to content

Commit

Permalink
Make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
koskja committed Aug 28, 2022
1 parent f9f5b6f commit bbfd69b
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 40 deletions.
2 changes: 1 addition & 1 deletion feather/base/src/anvil/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub struct SuperflatLayer {
}

/// The type of world generator for a level.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum LevelGeneratorType {
Default,
Flat,
Expand Down
2 changes: 1 addition & 1 deletion feather/blocks/generator/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl PropertyStore {

fn update_name(name: &str) -> &str {
match NAME_OVERRIDES.get(&name) {
Some(x) => *x,
Some(x) => x,
None => name,
}
}
Expand Down
25 changes: 6 additions & 19 deletions feather/common/src/block_break.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,29 +180,16 @@ impl ActiveBreaker {
.iter()
.find_map(|(item, speed)| {
equipped_item
.map(|e| {
if e.item() == *item {
Some(*speed)
} else {
None
}
.and_then(|e| {
bool::then_some(e.item() == *item, *speed)
})
.flatten()
})
.unwrap_or(1.0);
let effi_level = equipped_item
.map(ItemStack::metadata)
.flatten()
.map(|meta| {
meta.enchantments().iter().find_map(|ench| {
if ench.kind() == EnchantmentKind::Efficiency {
Some(ench.level())
} else {
None
}
})
})
.flatten();
.and_then(ItemStack::metadata)
.and_then(|meta| {
meta.get_enchantment_level(EnchantmentKind::Efficiency)
});
let effi_speed = effi_level.map(|level| level * level + 1).unwrap_or(0) as f32;
let damage = if harvestable {
(dig_multiplier + effi_speed) / block.hardness() / 30.0
Expand Down
2 changes: 1 addition & 1 deletion feather/datapacks/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl NamespacedId {
}

/// Error returned when a namespaced ID was formatted incorrectly.
#[derive(Debug, thiserror::Error, PartialEq)]
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
pub enum ParseError {
#[error("'{0}' is not a valid character for namespaces")]
InvalidNamespaceChar(char),
Expand Down
2 changes: 1 addition & 1 deletion feather/protocol/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ impl<'a> Readable for LengthInferredVecU8<'a> {

impl<'a> Writeable for LengthInferredVecU8<'a> {
fn write(&self, buffer: &mut Vec<u8>, _version: ProtocolVersion) -> anyhow::Result<()> {
buffer.extend_from_slice(&*self.0);
buffer.extend_from_slice(&self.0);
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion feather/server/src/initial_handler/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod bungeecord;
mod velocity;

/// IP forwarding data received from the proxy.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub struct ProxyData {
/// IP address of the proxy.
pub host: String,
Expand Down
2 changes: 1 addition & 1 deletion feather/server/src/packet_handlers/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn handle_player_digging(
let hotbar_slot = game.ecs.get::<HotbarSlot>(player)?.get();
let main_hand = window.item(SLOT_HOTBAR_OFFSET + hotbar_slot)?;
*breaker = BlockBreaker::Active(
ActiveBreaker::new(&mut game.world, packet.position, main_hand.item_stack())
ActiveBreaker::new(&mut game.world, packet.position, main_hand.option_ref())
.unwrap(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion feather/server/src/packet_handlers/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn handle_click_window(
}
client.set_cursor_slot(window.cursor_item());

client.send_window_items(&*window);
client.send_window_items(&window);

result
}
Expand Down
3 changes: 3 additions & 0 deletions libcraft/items/src/item_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ impl ItemStack {
self.item.stack_size()
}

#[must_use]
pub fn metadata(&self) -> Option<&ItemStackMeta> {
self.meta.as_ref()
}
Expand Down Expand Up @@ -403,9 +404,11 @@ impl ItemStackMeta {
self.enchantments.push(Enchantment::new(ench, level));
}
}
#[must_use]
pub fn enchantments(&self) -> &[Enchantment] {
&self.enchantments
}
#[must_use]
pub fn enchantments_mut(&mut self) -> &mut Vec<Enchantment> {
&mut self.enchantments
}
Expand Down
4 changes: 2 additions & 2 deletions libcraft/text/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum TextConversionError {
InvalidStyle(String),
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Color {
DarkRed,
Expand Down Expand Up @@ -304,7 +304,7 @@ where
}
}

impl<'a> From<&Translate> for String {
impl From<&Translate> for String {
fn from(translate: &Translate) -> Self {
match translate {
Translate::ChatTypeText => "chat.type.text",
Expand Down
10 changes: 5 additions & 5 deletions libcraft/text/src/text/markdown/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::slice::Iter;

pub type Span<'a> = LocatedSpan<&'a str>;

#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct LexToken<'a> {
pub tok: LexTokenType<'a>,
pub span: Span<'a>,
Expand All @@ -34,7 +34,7 @@ pub enum LexTokenType<'a> {
Word(&'a str),
}

#[derive(Debug, PartialEq, Clone, Copy)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct Tokens<'a> {
pub tok: &'a [LexToken<'a>],
start: usize,
Expand Down Expand Up @@ -159,7 +159,7 @@ pub fn lex_control_word(input: Span) -> IResult<Span, LexToken, VerboseError<Spa

pub fn lex_spaces(input: Span) -> IResult<Span, LexToken, VerboseError<Span>> {
map(space1, |s: Span| {
LexToken::new(s, LexTokenType::Space(*s.fragment()))
LexToken::new(s, LexTokenType::Space(s.fragment()))
})(input)
}

Expand All @@ -173,13 +173,13 @@ pub fn valid_word(input: Span) -> IResult<Span, Span, VerboseError<Span>> {

pub fn lex_word(input: Span) -> IResult<Span, LexToken, VerboseError<Span>> {
map(valid_word, |s: Span| {
LexToken::new(s, LexTokenType::Word(*s.fragment()))
LexToken::new(s, LexTokenType::Word(s.fragment()))
})(input)
}

pub fn lex_color_code(input: Span) -> IResult<Span, LexToken, VerboseError<Span>> {
map(preceded(peek(tag("#")), take(7usize)), |code: Span| {
LexToken::new(code, LexTokenType::Word(*code.fragment()))
LexToken::new(code, LexTokenType::Word(code.fragment()))
})(input)
}

Expand Down
2 changes: 1 addition & 1 deletion libcraft/text/src/text/markdown/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use nom::{Err, IResult};

pub mod events;

#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct DynamicSpan {
pub fragment: String,
pub col: usize,
Expand Down
4 changes: 2 additions & 2 deletions libcraft/text/src/text/markdown/parser/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ pub enum EventParseError<'a> {
InvalidEventAction(&'a str),
}

#[derive(Debug, PartialEq, Copy, Clone)]
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum EventType {
OnHover,
OnClick,
}

#[derive(Debug, PartialEq, Copy, Clone)]
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum EventAction {
ShowText,
OpenUrl,
Expand Down
1 change: 1 addition & 0 deletions quill/api/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl<Plugin> Setup<Plugin> {
///
/// The function should take as parameters your
/// plugin instance and an `&mut Game` and return nothing.
#[allow(clippy::type_complexity)]
pub fn add_system<T: FnMut(&mut Plugin, &mut Game)>(&mut self, system: T) -> &mut Self {
let system: Box<dyn FnMut(&mut Plugin, &mut Game)> = Box::new(system);
let system_data = Box::leak(Box::new(system)) as *mut Box<_> as *mut u8;
Expand Down
4 changes: 2 additions & 2 deletions quill/common/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Name {
}

pub fn as_str(&self) -> &str {
&*self
self
}
}

Expand Down Expand Up @@ -73,7 +73,7 @@ impl CustomName {
}

pub fn as_str(&self) -> &str {
&*self
self
}

pub fn as_mut_str(&mut self) -> &mut str {
Expand Down
2 changes: 1 addition & 1 deletion quill/plugin-format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'a> PluginFile<'a> {
/// this is the contents of the shared library
/// containing the plugin.
pub fn module(&self) -> &[u8] {
&*self.module
&self.module
}

pub fn metadata(&self) -> &PluginMetadata {
Expand Down
2 changes: 1 addition & 1 deletion quill/plugin-format/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde_with::{serde_as, DisplayFromStr};
use target_lexicon::Triple;

/// A plugin's metadata, stored alongside its WASM module.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PluginMetadata {
/// Plugin name, no spaces
pub name: String,
Expand Down

0 comments on commit bbfd69b

Please sign in to comment.