Skip to content

Commit

Permalink
Update to Rust edition 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Feb 20, 2025
1 parent b428fdc commit 1fb2be4
Show file tree
Hide file tree
Showing 208 changed files with 462 additions and 439 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ members = [

[workspace.package]
version = "0.1.0"
edition = "2021"
edition = "2024"


[profile.dev]
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "pumpkin-fuzz"
version = "0.0.0"
publish = false
edition = "2021"
edition = "2024"

[package.metadata]
cargo-fuzz = true
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-api-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use proc_macro::TokenStream;
use quote::quote;
use std::sync::LazyLock;
use std::sync::Mutex;
use syn::{parse_macro_input, parse_quote, ImplItem, ItemFn, ItemImpl, ItemStruct};
use syn::{ImplItem, ItemFn, ItemImpl, ItemStruct, parse_macro_input, parse_quote};

static PLUGIN_METHODS: LazyLock<Mutex<Vec<String>>> = LazyLock::new(|| Mutex::new(Vec::new()));

Expand Down
11 changes: 6 additions & 5 deletions pumpkin-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chunk::ChunkConfig;
use log::warn;
use logging::LoggingConfig;
use pumpkin_util::{Difficulty, GameMode, PermissionLvl};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde::{Deserialize, Serialize, de::DeserializeOwned};

use std::{
env, fs,
Expand Down Expand Up @@ -184,14 +184,15 @@ impl LoadConfiguration for BasicConfiguration {
}

fn validate(&self) {
let min = unsafe { NonZeroU8::new_unchecked(2) };
let max = unsafe { NonZeroU8::new_unchecked(32) };

assert!(
self.view_distance
.ge(unsafe { &NonZeroU8::new_unchecked(2) }),
self.view_distance.ge(&min),
"View distance must be at least 2"
);
assert!(
self.view_distance
.le(unsafe { &NonZeroU8::new_unchecked(32) }),
self.view_distance.le(&max),
"View distance must be less than 32"
);
if self.online_mode {
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-data/build/entity_type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use proc_macro2::TokenStream;
use quote::{format_ident, quote, ToTokens};
use quote::{ToTokens, format_ident, quote};
use serde::Deserialize;
use syn::LitInt;

Expand Down
2 changes: 1 addition & 1 deletion pumpkin-data/build/item.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use heck::ToShoutySnakeCase;
use proc_macro2::{Span, TokenStream};
use quote::{format_ident, quote, ToTokens};
use quote::{ToTokens, format_ident, quote};
use syn::{Ident, LitBool, LitFloat, LitInt, LitStr};

include!("../src/tag.rs");
Expand Down
4 changes: 2 additions & 2 deletions pumpkin-inventory/src/crafting.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use pumpkin_data::{
item::Item,
tag::{get_tag_values, RegistryEntryList, RegistryKey, TagType},
tag::{RegistryEntryList, RegistryKey, TagType, get_tag_values},
};
use pumpkin_registry::{flatten_3x3, RecipeResult, RECIPES};
use pumpkin_registry::{RECIPES, RecipeResult, flatten_3x3};
use pumpkin_world::item::ItemStack;
use rayon::prelude::*;

Expand Down
8 changes: 2 additions & 6 deletions pumpkin-inventory/src/open_container.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::crafting::check_if_matches_crafting;
use crate::Container;
use crate::crafting::check_if_matches_crafting;
use pumpkin_data::screen::WindowType;
use pumpkin_util::math::position::BlockPos;
use pumpkin_world::block::registry::Block;
Expand Down Expand Up @@ -34,11 +34,7 @@ impl OpenContainer {

pub fn remove_player(&mut self, player_id: i32) {
if let Some(index) = self.players.iter().enumerate().find_map(|(index, id)| {
if *id == player_id {
Some(index)
} else {
None
}
if *id == player_id { Some(index) } else { None }
}) {
self.players.remove(index);
}
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-inventory/src/player.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::container_click::MouseClick;
use crate::crafting::check_if_matches_crafting;
use crate::{handle_item_change, Container, InventoryError, WindowType};
use crate::{Container, InventoryError, WindowType, handle_item_change};
use pumpkin_data::item::Item;
use pumpkin_world::item::ItemStack;
use std::iter::Chain;
Expand Down
23 changes: 12 additions & 11 deletions pumpkin-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use proc_macro::TokenStream;
use pumpkin_data::item::Item;
use quote::quote;
use syn::{
Block, Expr, Field, Fields, ItemStruct, Stmt,
parse::{Nothing, Parser},
parse_macro_input, Block, Expr, Field, Fields, ItemStruct, Stmt,
parse_macro_input,
};

extern crate proc_macro;
Expand Down Expand Up @@ -161,14 +162,14 @@ pub fn client_packet(input: TokenStream, item: TokenStream) -> TokenStream {
let input: proc_macro2::TokenStream = input.into();
let item: proc_macro2::TokenStream = item.into();

let gen = quote! {
let code = quote! {
#item
impl #impl_generics crate::bytebuf::packet::Packet for #name #ty_generics {
const PACKET_ID: i32 = #input;
}
};

gen.into()
code.into()
}

#[proc_macro_attribute]
Expand All @@ -180,14 +181,14 @@ pub fn server_packet(input: TokenStream, item: TokenStream) -> TokenStream {
let input: proc_macro2::TokenStream = input.into();
let item: proc_macro2::TokenStream = item.into();

let gen = quote! {
let code = quote! {
#item
impl #impl_generics crate::bytebuf::packet::Packet for #name #ty_generics {
const PACKET_ID: i32 = #input;
}
};

gen.into()
code.into()
}

#[proc_macro_attribute]
Expand All @@ -205,15 +206,15 @@ pub fn pumpkin_block(input: TokenStream, item: TokenStream) -> TokenStream {

let item: proc_macro2::TokenStream = item.into();

let gen = quote! {
let code = quote! {
#item
impl #impl_generics crate::block::pumpkin_block::BlockMetadata for #name #ty_generics {
const NAMESPACE: &'static str = #namespace;
const ID: &'static str = #id;
}
};

gen.into()
code.into()
}

#[proc_macro_attribute]
Expand All @@ -229,14 +230,14 @@ pub fn pumpkin_item(input: TokenStream, item: TokenStream) -> TokenStream {

let item: proc_macro2::TokenStream = item.into();

let gen = quote! {
let code = quote! {
#item
impl #impl_generics crate::item::pumpkin_item::ItemMetadata for #name #ty_generics {
const ID: u16 = #id;
}
};

gen.into()
code.into()
}

#[proc_macro_attribute]
Expand Down Expand Up @@ -351,7 +352,7 @@ pub fn block_property(input: TokenStream, item: TokenStream) -> TokenStream {
}
};

let gen = quote! {
let code = quote! {
#item
impl #impl_generics crate::block::properties::BlockPropertyMetadata for #name #ty_generics {
fn name(&self) -> &'static str {
Expand All @@ -372,7 +373,7 @@ pub fn block_property(input: TokenStream, item: TokenStream) -> TokenStream {
#extra
};

gen.into()
code.into()
}

mod block_state;
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-nbt/src/compound.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::deserializer::ReadAdaptor;
use crate::serializer::WriteAdaptor;
use crate::tag::NbtTag;
use crate::{get_nbt_string, Error, Nbt, END_ID};
use crate::{END_ID, Error, Nbt, get_nbt_string};
use std::io::{ErrorKind, Read, Write};
use std::vec::IntoIter;

Expand Down
2 changes: 1 addition & 1 deletion pumpkin-nbt/src/deserializer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::*;
use io::Read;
use serde::de::{self, DeserializeSeed, IntoDeserializer, MapAccess, SeqAccess, Visitor};
use serde::{forward_to_deserialize_any, Deserialize};
use serde::{Deserialize, forward_to_deserialize_any};

pub type Result<T> = std::result::Result<T, Error>;

Expand Down
2 changes: 1 addition & 1 deletion pumpkin-nbt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ impl_array!(nbt_byte_array, NBT_BYTE_ARRAY_TAG);
#[cfg(test)]
mod test {

use crate::Error;
use crate::deserializer::from_bytes;
use crate::nbt_byte_array;
use crate::nbt_int_array;
use crate::nbt_long_array;
use crate::serializer::to_bytes;
use crate::serializer::to_bytes_named;
use crate::Error;
use crate::{deserializer::from_bytes_unnamed, serializer::to_bytes_unnamed};
use serde::{Deserialize, Serialize};

Expand Down
6 changes: 3 additions & 3 deletions pumpkin-nbt/src/serializer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use serde::ser::Impossible;
use serde::{ser, Serialize};
use serde::{Serialize, ser};
use std::io::Write;

use crate::tag::NbtTag;
use crate::{
Error, BYTE_ARRAY_ID, BYTE_ID, COMPOUND_ID, DOUBLE_ID, END_ID, FLOAT_ID, INT_ARRAY_ID, INT_ID,
BYTE_ARRAY_ID, BYTE_ID, COMPOUND_ID, DOUBLE_ID, END_ID, Error, FLOAT_ID, INT_ARRAY_ID, INT_ID,
LIST_ID, LONG_ARRAY_ID, LONG_ID, NBT_ARRAY_TAG, NBT_BYTE_ARRAY_TAG, NBT_INT_ARRAY_TAG,
NBT_LONG_ARRAY_TAG, SHORT_ID, STRING_ID,
};
Expand Down Expand Up @@ -393,7 +393,7 @@ impl<W: Write> ser::Serializer for &mut Serializer<W> {
_ => {
return Err(Error::SerdeError(
"Array supports only byte, int, long".to_string(),
))
));
}
};

Expand Down
8 changes: 4 additions & 4 deletions pumpkin-protocol/src/bytebuf/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use core::str;

use crate::{
FixedBitSet,
codec::{
bit_set::BitSet, identifier::Identifier, var_int::VarInt, var_long::VarLong, Codec,
DecodeError,
Codec, DecodeError, bit_set::BitSet, identifier::Identifier, var_int::VarInt,
var_long::VarLong,
},
FixedBitSet,
};
use bytes::{Buf, BufMut};

Expand Down Expand Up @@ -279,8 +279,8 @@ mod test {
use serde::{Deserialize, Serialize};

use crate::{
bytebuf::{deserializer, serializer},
VarInt,
bytebuf::{deserializer, serializer},
};

#[test]
Expand Down
6 changes: 3 additions & 3 deletions pumpkin-protocol/src/bytebuf/packet.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use bytes::{Buf, BufMut};
use serde::{de::DeserializeOwned, Serialize};
use serde::{Serialize, de::DeserializeOwned};

use crate::{codec::var_int::VarIntType, ClientPacket, ServerPacket};
use crate::{ClientPacket, ServerPacket, codec::var_int::VarIntType};

use super::{deserializer, serializer, ReadingError};
use super::{ReadingError, deserializer, serializer};

pub trait Packet {
const PACKET_ID: VarIntType;
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/bytebuf/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::fmt::Display;

use bytes::BufMut;
use serde::{
ser::{self},
Serialize,
ser::{self},
};
use thiserror::Error;

Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/config/known_packs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bytes::BufMut;
use pumpkin_data::packet::clientbound::CONFIG_SELECT_KNOWN_PACKS;
use pumpkin_macros::client_packet;

use crate::{bytebuf::ByteBufMut, ClientPacket, KnownPack};
use crate::{ClientPacket, KnownPack, bytebuf::ByteBufMut};

#[client_packet(CONFIG_SELECT_KNOWN_PACKS)]
pub struct CKnownPacks<'a> {
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/config/registry_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use pumpkin_data::packet::clientbound::CONFIG_REGISTRY_DATA;
use pumpkin_macros::client_packet;
use serde::Serialize;

use crate::{bytebuf::ByteBufMut, codec::identifier::Identifier, ClientPacket};
use crate::{ClientPacket, bytebuf::ByteBufMut, codec::identifier::Identifier};

#[client_packet(CONFIG_REGISTRY_DATA)]
pub struct CRegistryData<'a> {
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/config/store_cookie.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{codec::identifier::Identifier, VarInt};
use crate::{VarInt, codec::identifier::Identifier};
use pumpkin_data::packet::clientbound::CONFIG_STORE_COOKIE;
use pumpkin_macros::client_packet;

Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/config/update_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use pumpkin_macros::client_packet;
use pumpkin_world::block::registry;

use crate::{
ClientPacket,
bytebuf::ByteBufMut,
codec::{identifier::Identifier, var_int::VarInt},
ClientPacket,
};

#[client_packet(CONFIG_UPDATE_TAGS)]
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/login/login_success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bytes::BufMut;
use pumpkin_data::packet::clientbound::LOGIN_LOGIN_FINISHED;
use pumpkin_macros::client_packet;

use crate::{bytebuf::ByteBufMut, ClientPacket, Property};
use crate::{ClientPacket, Property, bytebuf::ByteBufMut};

#[client_packet(LOGIN_LOGIN_FINISHED)]
pub struct CLoginSuccess<'a> {
Expand Down
6 changes: 3 additions & 3 deletions pumpkin-protocol/src/client/play/chunk_data.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::{bytebuf::ByteBufMut, codec::bit_set::BitSet, ClientPacket, VarInt};
use crate::{ClientPacket, VarInt, bytebuf::ByteBufMut, codec::bit_set::BitSet};

use bytes::{BufMut, BytesMut};
use pumpkin_data::packet::clientbound::PLAY_LEVEL_CHUNK_WITH_LIGHT;
use pumpkin_macros::client_packet;
use pumpkin_world::{
chunk::{ChunkData, SUBCHUNKS_COUNT},
DIRECT_PALETTE_BITS,
chunk::{ChunkData, SUBCHUNKS_COUNT},
};

#[client_packet(PLAY_LEVEL_CHUNK_WITH_LIGHT)]
Expand Down Expand Up @@ -73,7 +73,7 @@ impl ClientPacket for CChunkData<'_> {
.iter()
.position(|b| b == block)
.expect("Its just got added, ofc it should be there");
out_long = out_long << block_size | (index as i64);
out_long = (out_long << block_size) | (index as i64);
}
data_buf.put_i64(out_long);
}
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/play/command_suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use pumpkin_data::packet::clientbound::PLAY_COMMAND_SUGGESTIONS;
use pumpkin_macros::client_packet;
use pumpkin_util::text::TextComponent;

use crate::{bytebuf::ByteBufMut, ClientPacket, VarInt};
use crate::{ClientPacket, VarInt, bytebuf::ByteBufMut};

#[client_packet(PLAY_COMMAND_SUGGESTIONS)]
pub struct CCommandSuggestions {
Expand Down
Loading

0 comments on commit 1fb2be4

Please sign in to comment.