Fix warnings

This commit is contained in:
Joshua Barretto 2024-01-19 20:14:32 +00:00
parent 5260c82c4a
commit e5aa8cd3b7
4 changed files with 20 additions and 23 deletions

View File

@ -116,7 +116,7 @@ impl BlockKind {
/// # Format
///
/// ```
/// ```ignore
/// BBBBBBBB CCCCCCCC AAAAAIII IIIIIIII
/// ```
/// - `0..8` : BlockKind
@ -194,13 +194,6 @@ impl Block {
#[inline]
pub const fn air(sprite: SpriteKind) -> Self { Self::unfilled(BlockKind::Air, sprite) }
#[inline]
pub const fn lava(sprite: SpriteKind) -> Self {
// TODO: Is this valid? I don't think so, lava is filled. Debug panic will catch
// it if not though.
Self::unfilled(BlockKind::Lava, sprite)
}
#[inline]
pub const fn empty() -> Self { Self::air(SpriteKind::Empty) }
@ -260,7 +253,7 @@ impl Block {
pub fn get_attr<A: sprite::Attribute>(&self) -> Result<A, sprite::AttributeError<A::Error>> {
match self.sprite_category() {
Some(category) => category.read_attr(*self),
None => return Err(sprite::AttributeError::NotPresent),
None => Err(sprite::AttributeError::NotPresent),
}
}
@ -271,7 +264,7 @@ impl Block {
}
#[inline(always)]
pub(super) const fn to_be_u32(&self) -> u32 {
pub(super) const fn to_be_u32(self) -> u32 {
u32::from_be_bytes([self.kind as u8, self.data[0], self.data[1], self.data[2]])
}
@ -666,7 +659,7 @@ impl Block {
}
#[inline]
pub fn to_u32(&self) -> u32 {
pub fn to_u32(self) -> u32 {
u32::from_le_bytes([self.kind as u8, self.data[0], self.data[1], self.data[2]])
}
}

View File

@ -52,7 +52,10 @@ use hashbrown::HashMap;
use lazy_static::lazy_static;
use num_derive::FromPrimitive;
use serde::{Deserialize, Serialize};
use std::{convert::TryFrom, fmt};
use std::{
convert::{Infallible, TryFrom},
fmt,
};
use strum::EnumIter;
use vek::*;
@ -323,8 +326,6 @@ sprites! {
},
}
use core::convert::Infallible;
attributes! {
Ori { bits: 4, err: Infallible, from: |bits| Ok(Self(bits as u8)), into: |Ori(x)| x as u16 },
Growth { bits: 4, err: Infallible, from: |bits| Ok(Self(bits as u8)), into: |Growth(x)| x as u16 },

View File

@ -128,7 +128,7 @@ macro_rules! sprites {
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize, EnumIter, FromPrimitive)]
#[repr(u32)]
pub enum SpriteKind {
$($($sprite_name = crate::terrain::sprite::gen_discriminant(crate::terrain::sprite::Category::$category_name, $sprite_id),)*)*
$($($sprite_name = $crate::terrain::sprite::gen_discriminant($crate::terrain::sprite::Category::$category_name, $sprite_id),)*)*
}
);
@ -197,12 +197,15 @@ macro_rules! attributes {
}
}
$(impl Attribute for $name {
const INDEX: usize = Attributes::$name as usize;
const BITS: u8 = $bits;
type Error = $err;
#[inline(always)] fn from_bits(bits: u16) -> Result<Self, Self::Error> { $from_bits(bits) }
#[inline(always)] fn into_bits(self) -> u16 { $into_bits(self) }
})*
$(
#[allow(clippy::all)]
impl Attribute for $name {
const INDEX: usize = Attributes::$name as usize;
const BITS: u8 = $bits;
type Error = $err;
#[inline(always)] fn from_bits(bits: u16) -> Result<Self, Self::Error> { $from_bits(bits) }
#[inline(always)] fn into_bits(self) -> u16 { $into_bits(self) }
}
)*
};
}

View File

@ -212,7 +212,7 @@ impl TryFrom<HashMap<SpriteKind, Option<SpriteConfig<String>>>> for SpriteSpec {
type Error = SpritesMissing;
fn try_from(
mut map: HashMap<SpriteKind, Option<SpriteConfig<String>>>,
map: HashMap<SpriteKind, Option<SpriteConfig<String>>>,
) -> Result<Self, Self::Error> {
Ok(Self(map))